-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpage.tsx
117 lines (102 loc) · 3.45 KB
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
'use client';
import { useRef, useContext, useState } from 'react';
import Image from 'next/image';
import { motion } from 'framer-motion';
import { AuthChoiceModal } from '@/components/auth-choice-modal';
import { useAuthContext } from '@/providers/AuthProvider';
import { ProjectsSection } from '@/components/root/ProjectsSection';
import { PromptForm, PromptFormRef } from '@/components/root/prompt-form';
import { ProjectContext } from '@/components/chat/code-engine/project-context';
export default function HomePage() {
const [showAuthChoice, setShowAuthChoice] = useState(false);
const promptFormRef = useRef<PromptFormRef>(null);
const { isAuthorized } = useAuthContext();
const { createProjectFromPrompt, isLoading } = useContext(ProjectContext);
const handleSubmit = async () => {
if (!promptFormRef.current) return;
// Get form data from the prompt form
const { message, isPublic, model } = promptFormRef.current.getPromptData();
if (!message.trim()) return;
try {
// Create the project
const result = await createProjectFromPrompt(message, isPublic, model);
// If successful, clear the input
if (result) {
promptFormRef.current.clearMessage();
// Note: No need to navigate here as the ProjectContext's onCompleted handler
// in the createProject mutation will handle navigation to the chat page
}
} catch (error) {
console.error('Error creating project:', error);
// Error handling is done via toast in ProjectContext
}
};
return (
<div className="pt-32 pb-24 px-6 ">
<motion.div
className="flex flex-col items-center"
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.5 }}
>
<div className="mb-6">
<Image
src="/codefox.svg"
alt="CodeFox Logo"
width={120}
height={120}
className="h-32 w-auto"
/>
</div>
<div className="mb-16">
<div className="flex flex-col items-center">
<p className="text-5xl font-medium text-primary-600 dark:text-primary-400 mb-3">
Sentence to a project in seconds.
</p>
<p className="text-xl text-gray-600 dark:text-gray-400">
Codefox built AI agents crew for you to create your next project
</p>
</div>
</div>
<div className="w-full mb-12">
<PromptForm
ref={promptFormRef}
isAuthorized={isAuthorized}
onSubmit={handleSubmit}
onAuthRequired={() => setShowAuthChoice(true)}
isLoading={isLoading}
/>
</div>
<div className="w-full mb-24">
<ProjectsSection />
</div>
</motion.div>
{/* Modals */}
<AuthChoiceModal
isOpen={showAuthChoice}
onClose={() => setShowAuthChoice(false)}
onSignUpClick={() => {
setShowAuthChoice(false);
}}
onSignInClick={() => {
setShowAuthChoice(false);
}}
/>
{/* Add this to your global CSS for the subtle pulse animation */}
<style jsx global>{`
.animate-pulse-subtle {
animation: pulse-subtle 2s infinite;
}
@keyframes pulse-subtle {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.85;
}
}
`}</style>
</div>
);
}