ZuhairAhmed commited on
Commit
7bc08d9
·
1 Parent(s): 11e46c7
Files changed (5) hide show
  1. .dockerignore +2 -0
  2. .npmrc +1 -0
  3. Dockerfile +15 -0
  4. src/app/globals.css +49 -46
  5. src/webzero/chat-page.tsx +288 -199
.dockerignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .next
2
+ node_modules
.npmrc ADDED
@@ -0,0 +1 @@
 
 
1
+ legacy-peer-deps=true
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:18-alpine
2
+
3
+ WORKDIR /usr/src/app
4
+
5
+ COPY package.json package-lock.json .npmrc ./
6
+
7
+ RUN npm install
8
+
9
+ COPY . .
10
+
11
+ EXPOSE 3000
12
+
13
+ ENV NODE_ENV=development
14
+
15
+ CMD ["npm", "run", "dev"]
src/app/globals.css CHANGED
@@ -2,10 +2,6 @@
2
  @tailwind components;
3
  @tailwind utilities;
4
 
5
- body {
6
- font-family: Arial, Helvetica, sans-serif;
7
- }
8
-
9
  @layer base {
10
  :root {
11
  --background: 0 0% 100%;
@@ -27,21 +23,9 @@ body {
27
  --border: 240 5.9% 90%;
28
  --input: 240 5.9% 90%;
29
  --ring: 240 10% 3.9%;
30
- --chart-1: 12 76% 61%;
31
- --chart-2: 173 58% 39%;
32
- --chart-3: 197 37% 24%;
33
- --chart-4: 43 74% 66%;
34
- --chart-5: 27 87% 67%;
35
  --radius: 0.5rem;
36
- --sidebar-background: 0 0% 98%;
37
- --sidebar-foreground: 240 5.3% 26.1%;
38
- --sidebar-primary: 240 5.9% 10%;
39
- --sidebar-primary-foreground: 0 0% 98%;
40
- --sidebar-accent: 240 4.8% 95.9%;
41
- --sidebar-accent-foreground: 240 5.9% 10%;
42
- --sidebar-border: 220 13% 91%;
43
- --sidebar-ring: 217.2 91.2% 59.8%;
44
  }
 
45
  .dark {
46
  --background: 240 10% 3.9%;
47
  --foreground: 0 0% 98%;
@@ -62,19 +46,6 @@ body {
62
  --border: 240 3.7% 15.9%;
63
  --input: 240 3.7% 15.9%;
64
  --ring: 240 4.9% 83.9%;
65
- --chart-1: 220 70% 50%;
66
- --chart-2: 160 60% 45%;
67
- --chart-3: 30 80% 55%;
68
- --chart-4: 280 65% 60%;
69
- --chart-5: 340 75% 55%;
70
- --sidebar-background: 240 5.9% 10%;
71
- --sidebar-foreground: 240 4.8% 95.9%;
72
- --sidebar-primary: 224.3 76.3% 48%;
73
- --sidebar-primary-foreground: 0 0% 100%;
74
- --sidebar-accent: 240 3.7% 15.9%;
75
- --sidebar-accent-foreground: 240 4.8% 95.9%;
76
- --sidebar-border: 240 3.7% 15.9%;
77
- --sidebar-ring: 217.2 91.2% 59.8%;
78
  }
79
  }
80
 
@@ -87,32 +58,64 @@ body {
87
  }
88
  }
89
 
90
- .flex2 {
91
- flex: 2;
 
 
 
92
  }
93
 
94
- .mw66 {
95
- max-width: 66%;
96
  }
97
 
98
- .loader-light {
99
- background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"><circle fill="%23000000" stroke="%23000000" stroke-width="15" r="15" cx="40" cy="65"><animate attributeName="cy" calcMode="spline" dur="2" values="65;135;65;" keySplines=".5 0 .5 1;.5 0 .5 1" repeatCount="indefinite" begin="-.4"></animate></circle><circle fill="%23000000" stroke="%23000000" stroke-width="15" r="15" cx="100" cy="65"><animate attributeName="cy" calcMode="spline" dur="2" values="65;135;65;" keySplines=".5 0 .5 1;.5 0 .5 1" repeatCount="indefinite" begin="-.2"></animate></circle><circle fill="%23000000" stroke="%23000000" stroke-width="15" r="15" cx="160" cy="65"><animate attributeName="cy" calcMode="spline" dur="2" values="65;135;65;" keySplines=".5 0 .5 1;.5 0 .5 1" repeatCount="indefinite" begin="0"></animate></circle></svg>');
 
 
 
 
 
 
100
  }
101
 
102
- .loader-dark {
103
- background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"><circle fill="%23FFFFFF" stroke="%23FFFFFF" stroke-width="15" r="15" cx="40" cy="65"><animate attributeName="cy" calcMode="spline" dur="2" values="65;135;65;" keySplines=".5 0 .5 1;.5 0 .5 1" repeatCount="indefinite" begin="-.4"></animate></circle><circle fill="%23FFFFFF" stroke="%23FFFFFF" stroke-width="15" r="15" cx="100" cy="65"><animate attributeName="cy" calcMode="spline" dur="2" values="65;135;65;" keySplines=".5 0 .5 1;.5 0 .5 1" repeatCount="indefinite" begin="-.2"></animate></circle><circle fill="%23FFFFFF" stroke="%23FFFFFF" stroke-width="15" r="15" cx="160" cy="65"><animate attributeName="cy" calcMode="spline" dur="2" values="65;135;65;" keySplines=".5 0 .5 1;.5 0 .5 1" repeatCount="indefinite" begin="0"></animate></circle></svg>');
 
 
 
 
 
104
  }
105
 
106
- .preview-scroll {
107
- height: calc(100vh - 10rem);
 
108
  }
109
 
110
- .chat-scroll {
111
- height: calc(100vh - 4rem);
112
  }
113
 
114
- .loader {
115
- height: 6rem;
116
- width: 6rem;
117
- justify-self: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  }
 
2
  @tailwind components;
3
  @tailwind utilities;
4
 
 
 
 
 
5
  @layer base {
6
  :root {
7
  --background: 0 0% 100%;
 
23
  --border: 240 5.9% 90%;
24
  --input: 240 5.9% 90%;
25
  --ring: 240 10% 3.9%;
 
 
 
 
 
26
  --radius: 0.5rem;
 
 
 
 
 
 
 
 
27
  }
28
+
29
  .dark {
30
  --background: 240 10% 3.9%;
31
  --foreground: 0 0% 98%;
 
46
  --border: 240 3.7% 15.9%;
47
  --input: 240 3.7% 15.9%;
48
  --ring: 240 4.9% 83.9%;
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  }
50
  }
51
 
 
58
  }
59
  }
60
 
61
+ html,
62
+ body,
63
+ #__next {
64
+ height: 100%;
65
+ overflow: hidden;
66
  }
67
 
68
+ .chat-scroll {
69
+ height: calc(100vh - 8rem);
70
  }
71
 
72
+ .loader {
73
+ border: 4px solid hsl(var(--muted));
74
+ border-top: 4px solid hsl(var(--primary));
75
+ border-radius: 50%;
76
+ width: 40px;
77
+ height: 40px;
78
+ animation: spin 1s linear infinite;
79
+ margin: 20px auto;
80
  }
81
 
82
+ @keyframes spin {
83
+ 0% {
84
+ transform: rotate(0deg);
85
+ }
86
+ 100% {
87
+ transform: rotate(360deg);
88
+ }
89
  }
90
 
91
+ /* Custom scrollbar styles */
92
+ ::-webkit-scrollbar {
93
+ width: 8px;
94
  }
95
 
96
+ ::-webkit-scrollbar-track {
97
+ background: hsl(var(--background));
98
  }
99
 
100
+ ::-webkit-scrollbar-thumb {
101
+ background: hsl(var(--muted));
102
+ border-radius: 4px;
103
+ }
104
+
105
+ ::-webkit-scrollbar-thumb:hover {
106
+ background: hsl(var(--muted-foreground));
107
+ }
108
+
109
+ .fullscreen-preview {
110
+ top: 42px;
111
+ position: fixed;
112
+ left: 0;
113
+ right: 0;
114
+ bottom: 0;
115
+ z-index: 50;
116
+ background-color: hsl(var(--background));
117
+ }
118
+
119
+ .fullscreen-preview .border-b {
120
+ margin-top: -1px;
121
  }
src/webzero/chat-page.tsx CHANGED
@@ -1,6 +1,6 @@
1
  "use client";
2
 
3
- import { useState, useEffect } from "react";
4
  import { useTheme } from "next-themes";
5
  import {
6
  Code,
@@ -16,6 +16,12 @@ import {
16
  import { Button } from "@/components/ui/button";
17
  import { Textarea } from "@/components/ui/textarea";
18
  import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
 
 
 
 
 
 
19
  import { ScrollArea } from "@/components/ui/scroll-area";
20
  import { Message, PreviewState } from "@/lib/types";
21
  // @ts-expect-error
@@ -24,6 +30,20 @@ import { customOneDark, customOneLight, generateUUID } from "@/lib/utils";
24
  import DynamicFileRenderer from "@/webzero/preview";
25
  import ThemeToggle from "@/components/ThemeToggle";
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  const sendMessage = async (content: string) => {
28
  const response = await fetch("/api/new", {
29
  method: "POST",
@@ -67,56 +87,60 @@ const sendIteration = async (
67
  export function ChatPage() {
68
  const [message, setMessage] = useState("");
69
  const [isLoading, setIsLoading] = useState(false);
70
- const [chatHistory, setChatHistory] = useState<Message[]>([]);
71
- const [selectedMessage, setSelectedMessage] = useState<Message | null>(null);
 
 
 
72
  const [previewState, setPreviewState] = useState<PreviewState>({
73
  isFullscreen: false,
74
  isOpen: false,
75
  });
76
- const [previousDescription, setPreviousDescription] = useState<string>("");
77
 
78
  const { theme } = useTheme();
79
  const isDark = theme === "dark";
80
 
81
- useEffect(() => {
82
- const savedChatHistory = localStorage.getItem("chatHistory");
83
- if (savedChatHistory) {
84
- setChatHistory(JSON.parse(savedChatHistory));
85
- }
86
- }, []);
87
 
88
  useEffect(() => {
89
- localStorage.setItem("chatHistory", JSON.stringify(chatHistory));
90
- }, [chatHistory]);
91
 
92
  const handleSubmit = async (e: React.FormEvent) => {
93
  e.preventDefault();
94
  if (!message.trim()) return;
95
 
96
  setIsLoading(true);
97
- const newMessage: Message = {
98
  id: generateUUID().toString(),
99
  from: "user",
100
  content: message,
101
  };
102
 
103
- setChatHistory((prev) => [...prev, newMessage]);
104
  setMessage("");
105
 
106
  try {
107
  let response;
108
- if (selectedMessage && selectedMessage.from === "ai") {
109
  response = await sendIteration(
110
- previousDescription,
111
  message,
112
- selectedMessage.content
113
  );
114
  } else {
115
  response = await sendMessage(message);
116
  }
117
- setChatHistory((prev) => [...prev, response]);
118
- setPreviousDescription(message);
119
- setSelectedMessage(response);
 
 
 
120
  setPreviewState((prev) => ({ ...prev, isOpen: true }));
121
  } catch (error) {
122
  console.error("Error:", error);
@@ -126,7 +150,11 @@ export function ChatPage() {
126
  };
127
 
128
  const handleCopyCode = async (code: string) => {
129
- await navigator.clipboard.writeText(code);
 
 
 
 
130
  };
131
 
132
  const handleDownloadCode = (code: string, filename: string) => {
@@ -139,6 +167,13 @@ export function ChatPage() {
139
  URL.revokeObjectURL(url);
140
  };
141
 
 
 
 
 
 
 
 
142
  const toggleFullscreen = () => {
143
  setPreviewState((prev) => ({
144
  ...prev,
@@ -147,193 +182,247 @@ export function ChatPage() {
147
  };
148
 
149
  return (
150
- <div className={`min-h-screen flex ${isDark ? "dark" : ""}`}>
151
- <div className="flex flex-1 flex-col w-full">
152
- <header className="h-16 border-b flex items-center justify-between px-4">
153
- <ThemeToggle />
154
- </header>
155
-
156
- <div className="flex flex-1">
157
- <div className="flex flex-col flex-1 h-fit">
158
- <ScrollArea className="flex-1 p-4 h-[calc(100vh-8rem)]">
159
- {chatHistory.map((msg) => (
160
- <div
161
- key={msg.id}
162
- className={`mb-4 p-4 rounded-lg ${
163
- msg.from === "user"
164
- ? "bg-primary/10 ml-auto max-w-[80%]"
165
- : "bg-muted max-w-[80%]"
166
- } cursor-pointer hover:bg-muted/80 transition-colors`}
167
- onClick={() => {
168
- setSelectedMessage(msg);
169
- setPreviewState((prev) => ({ ...prev, isOpen: true }));
170
- }}
171
- >
172
- {msg.from === "user" ? (
173
- <div className="mb-2">{msg.content}</div>
174
- ) : (
175
- <CodeMessageCard
176
- onClick={() =>
177
- setPreviewState((prev) => ({ ...prev, isOpen: true }))
178
- }
179
- />
180
- )}
181
- </div>
182
- ))}
183
- </ScrollArea>
184
 
185
- <div className="border-t p-4">
 
 
 
 
186
  <form onSubmit={handleSubmit} className="relative">
187
- {isLoading ? (
188
- <div
189
- className={`loader ${
190
- isDark ? "loader-dark" : "loader-light"
191
- }`}
192
- />
193
- ) : (
194
- <>
195
- <Textarea
196
- value={message}
197
- onChange={(e) => setMessage(e.target.value)}
198
- placeholder={
199
- selectedMessage && selectedMessage.from === "ai"
200
- ? "Describe your iteration..."
201
- : "Ask webzero a question..."
202
- }
203
- className="min-h-[100px] pr-24 resize-none"
204
- />
205
- <div className="absolute top-2 right-3 flex items-center gap-2">
206
- <Button type="submit" size="icon">
207
- <Send className="h-4 w-4" />
208
- </Button>
209
- </div>
210
- </>
211
- )}
212
  </form>
213
  </div>
214
  </div>
215
-
216
- {previewState.isFullscreen && (
217
- <div className="fixed inset-0 bg-background/80 backdrop-blur-sm z-40" />
218
- )}
219
-
220
- {selectedMessage?.content &&
221
- selectedMessage.from === "ai" &&
222
- previewState.isOpen && (
223
- <div
224
- className={`border-l ${
225
- previewState.isFullscreen
226
- ? "fixed inset-0 z-50 bg-background"
227
- : "w-1/2"
228
- }`}
229
- >
230
- <Tabs defaultValue="preview" className="h-full flex flex-col">
231
- <div className="border-b px-4 flex justify-between items-center">
232
- <TabsList>
233
- <TabsTrigger
234
- value="preview"
235
- className="flex items-center gap-2"
236
  >
237
- <Eye className="h-4 w-4" />
238
- Preview
239
- </TabsTrigger>
240
-
241
- <TabsTrigger
242
- value="code"
243
- className="flex items-center gap-2"
244
- >
245
- <Code className="h-4 w-4" />
246
- Code
247
- </TabsTrigger>
248
- </TabsList>
249
-
250
- <div className="flex items-center gap-2">
251
- {previewState.isFullscreen && <ThemeToggle />}
252
- <Button
253
- variant="outline"
254
- size="sm"
255
- onClick={() => handleCopyCode(selectedMessage.content)}
256
- >
257
- <Copy className="h-4 w-4 mr-2" />
258
- Copy
259
- </Button>
260
-
261
- <Button
262
- variant="outline"
263
- size="sm"
264
- onClick={() =>
265
- handleDownloadCode(
266
- selectedMessage.content,
267
- `code-${selectedMessage.id}.tsx`
268
- )
269
- }
270
- >
271
- <Download className="h-4 w-4 mr-2" />
272
- Download
273
- </Button>
274
-
275
- <Button
276
- variant="ghost"
277
- size="icon"
278
- onClick={toggleFullscreen}
279
- >
280
- {previewState.isFullscreen ? (
281
- <Minimize2 className="h-4 w-4" />
282
- ) : (
283
- <Maximize2 className="h-4 w-4" />
284
- )}
285
- </Button>
286
-
287
- <Button
288
- variant="ghost"
289
- size="icon"
290
- onClick={() =>
291
- setPreviewState((prev) => ({
292
- ...prev,
293
- isOpen: false,
294
- }))
295
- }
296
- >
297
- <X className="h-4 w-4" />
298
- </Button>
299
  </div>
300
- </div>
301
-
302
- <TabsContent value="preview" className="flex-1 p-4">
303
- <ScrollArea className="preview-scroll">
304
- <DynamicFileRenderer id={selectedMessage.id} />
305
- </ScrollArea>
306
- </TabsContent>
307
-
308
- <TabsContent value="code" className="flex-1">
309
- <ScrollArea className="preview-scroll">
310
- <SyntaxHighlighter
311
- language="typescript"
312
- style={isDark ? customOneDark : customOneLight}
313
- className="!m-0 !bg-transparent"
314
- >
315
- {selectedMessage.content}
316
- </SyntaxHighlighter>
317
- </ScrollArea>
318
- </TabsContent>
319
- </Tabs>
 
 
 
 
 
 
 
 
 
 
 
 
 
320
  </div>
321
- )}
322
- </div>
323
- </div>
324
- </div>
325
- );
326
- }
327
 
328
- function CodeMessageCard({ onClick }: { onClick: () => void }) {
329
- return (
330
- <div
331
- onClick={onClick}
332
- className="bg-muted/50 p-3 rounded-lg mb-2 cursor-pointer hover:bg-muted/80 transition-colors flex items-center gap-2"
333
- >
334
- <FileCode2 />
335
- <div className="ml-2">
336
- <div className="font-semibold text-sm">Code File</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  </div>
338
  </div>
339
  );
 
1
  "use client";
2
 
3
+ import { useState, useEffect, useRef } from "react";
4
  import { useTheme } from "next-themes";
5
  import {
6
  Code,
 
16
  import { Button } from "@/components/ui/button";
17
  import { Textarea } from "@/components/ui/textarea";
18
  import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
19
+ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
20
+ import {
21
+ ResizableHandle,
22
+ ResizablePanel,
23
+ ResizablePanelGroup,
24
+ } from "@/components/ui/resizable";
25
  import { ScrollArea } from "@/components/ui/scroll-area";
26
  import { Message, PreviewState } from "@/lib/types";
27
  // @ts-expect-error
 
30
  import DynamicFileRenderer from "@/webzero/preview";
31
  import ThemeToggle from "@/components/ThemeToggle";
32
 
33
+ function CodeMessageCard({ onClick }: { onClick: () => void }) {
34
+ return (
35
+ <div
36
+ onClick={onClick}
37
+ className="bg-muted/50 p-3 rounded-lg mb-2 cursor-pointer flex items-center gap-2"
38
+ >
39
+ <FileCode2 />
40
+ <div className="ml-2">
41
+ <div className="font-semibold text-sm">Code File</div>
42
+ </div>
43
+ </div>
44
+ );
45
+ }
46
+
47
  const sendMessage = async (content: string) => {
48
  const response = await fetch("/api/new", {
49
  method: "POST",
 
87
  export function ChatPage() {
88
  const [message, setMessage] = useState("");
89
  const [isLoading, setIsLoading] = useState(false);
90
+ const [messages, setMessages] = useState<Message[]>([]);
91
+ const [currentIteration, setCurrentIteration] = useState<{
92
+ previousDescription: string;
93
+ currentCode: string;
94
+ } | null>(null);
95
  const [previewState, setPreviewState] = useState<PreviewState>({
96
  isFullscreen: false,
97
  isOpen: false,
98
  });
 
99
 
100
  const { theme } = useTheme();
101
  const isDark = theme === "dark";
102
 
103
+ const messagesEndRef = useRef<HTMLDivElement>(null);
104
+
105
+ const scrollToBottom = () => {
106
+ messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
107
+ };
 
108
 
109
  useEffect(() => {
110
+ scrollToBottom();
111
+ }, [messages]);
112
 
113
  const handleSubmit = async (e: React.FormEvent) => {
114
  e.preventDefault();
115
  if (!message.trim()) return;
116
 
117
  setIsLoading(true);
118
+ const newUserMessage: Message = {
119
  id: generateUUID().toString(),
120
  from: "user",
121
  content: message,
122
  };
123
 
124
+ setMessages((prev) => [...prev, newUserMessage]);
125
  setMessage("");
126
 
127
  try {
128
  let response;
129
+ if (currentIteration) {
130
  response = await sendIteration(
131
+ currentIteration.previousDescription,
132
  message,
133
+ currentIteration.currentCode
134
  );
135
  } else {
136
  response = await sendMessage(message);
137
  }
138
+
139
+ setMessages((prev) => [...prev, response]);
140
+ setCurrentIteration({
141
+ previousDescription: message,
142
+ currentCode: response.content,
143
+ });
144
  setPreviewState((prev) => ({ ...prev, isOpen: true }));
145
  } catch (error) {
146
  console.error("Error:", error);
 
150
  };
151
 
152
  const handleCopyCode = async (code: string) => {
153
+ try {
154
+ await navigator.clipboard.writeText(code);
155
+ } catch (error) {
156
+ console.error("Failed to copy code:", error);
157
+ }
158
  };
159
 
160
  const handleDownloadCode = (code: string, filename: string) => {
 
167
  URL.revokeObjectURL(url);
168
  };
169
 
170
+ const handleKeyDown = (e: React.KeyboardEvent) => {
171
+ if (e.key === "Enter" && !e.shiftKey) {
172
+ e.preventDefault();
173
+ handleSubmit(e);
174
+ }
175
+ };
176
+
177
  const toggleFullscreen = () => {
178
  setPreviewState((prev) => ({
179
  ...prev,
 
182
  };
183
 
184
  return (
185
+ <div className={`h-screen flex flex-col ${isDark ? "dark" : ""}`}>
186
+ <header className="h-16 border-b flex items-center justify-between px-4 bg-background z-10">
187
+ <h1 className="text-2xl font-bold">Web Zero</h1>
188
+ <ThemeToggle />
189
+ </header>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
 
191
+ <div className="flex-1 flex overflow-hidden">
192
+ {messages.length === 0 ? (
193
+ <div className="flex-1 flex flex-col items-center justify-center p-4">
194
+ <h2 className="text-3xl font-bold mb-4">Welcome to Web Zero</h2>
195
+ <div className="w-full max-w-md">
196
  <form onSubmit={handleSubmit} className="relative">
197
+ <Textarea
198
+ value={message}
199
+ onChange={(e) => setMessage(e.target.value)}
200
+ onKeyDown={handleKeyDown}
201
+ placeholder="Ask webzero a question..."
202
+ className="min-h-[100px] pr-16 resize-none"
203
+ />
204
+ <Button
205
+ type="submit"
206
+ size="icon"
207
+ className="absolute bottom-3 right-3"
208
+ disabled={isLoading}
209
+ >
210
+ <Send className="h-4 w-4" />
211
+ </Button>
 
 
 
 
 
 
 
 
 
 
212
  </form>
213
  </div>
214
  </div>
215
+ ) : (
216
+ <ResizablePanelGroup direction="horizontal" className="flex-1">
217
+ <ResizablePanel defaultSize={50} minSize={30}>
218
+ <div className="flex flex-col h-full">
219
+ <ScrollArea className="flex-1 p-4">
220
+ {messages.map((msg) => (
221
+ <div
222
+ key={msg.id}
223
+ className={`mb-4 flex ${
224
+ msg.from === "user" ? "justify-end" : "justify-start"
225
+ }`}
226
+ >
227
+ <div
228
+ className={`flex items-start gap-3 max-w-[80%] ${
229
+ msg.from === "user" ? "flex-row-reverse" : ""
230
+ }`}
 
 
 
 
 
231
  >
232
+ <Avatar>
233
+ <AvatarImage
234
+ src={
235
+ msg.from === "user"
236
+ ? "/user-avatar.png"
237
+ : "/ai-avatar.png"
238
+ }
239
+ />
240
+ <AvatarFallback>
241
+ {msg.from === "user" ? "U" : "AI"}
242
+ </AvatarFallback>
243
+ </Avatar>
244
+ <div
245
+ className={`p-3 rounded-lg ${
246
+ msg.from === "user"
247
+ ? "bg-primary text-primary-foreground"
248
+ : "bg-muted"
249
+ }`}
250
+ >
251
+ {msg.from === "user" ? (
252
+ <p>{msg.content}</p>
253
+ ) : (
254
+ <CodeMessageCard
255
+ onClick={() =>
256
+ setPreviewState((prev) => ({
257
+ ...prev,
258
+ isOpen: true,
259
+ }))
260
+ }
261
+ />
262
+ )}
263
+ </div>
264
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  </div>
266
+ ))}
267
+ <div ref={messagesEndRef} />
268
+ </ScrollArea>
269
+
270
+ <div className="border-t p-4">
271
+ <form onSubmit={handleSubmit} className="relative">
272
+ {isLoading ? (
273
+ <div className="loader" />
274
+ ) : (
275
+ <>
276
+ <Textarea
277
+ value={message}
278
+ onChange={(e) => setMessage(e.target.value)}
279
+ onKeyDown={handleKeyDown}
280
+ placeholder={
281
+ currentIteration
282
+ ? "Describe your iteration..."
283
+ : "Ask webzero a question..."
284
+ }
285
+ className="min-h-[100px] pr-16 resize-none"
286
+ />
287
+ <Button
288
+ type="submit"
289
+ size="icon"
290
+ className="absolute bottom-3 right-3"
291
+ disabled={isLoading}
292
+ >
293
+ <Send className="h-4 w-4" />
294
+ </Button>
295
+ </>
296
+ )}
297
+ </form>
298
+ </div>
299
  </div>
300
+ </ResizablePanel>
 
 
 
 
 
301
 
302
+ {messages[messages.length - 1]?.from === "ai" &&
303
+ previewState.isOpen && (
304
+ <>
305
+ <ResizableHandle />
306
+ <ResizablePanel defaultSize={50} minSize={30}>
307
+ <div
308
+ className={`h-full ${
309
+ previewState.isFullscreen ? "fullscreen-preview" : ""
310
+ }`}
311
+ >
312
+ <Tabs
313
+ defaultValue="preview"
314
+ className="h-full flex flex-col"
315
+ >
316
+ <div className="border-b px-4 flex justify-between items-center">
317
+ <TabsList>
318
+ <TabsTrigger
319
+ value="preview"
320
+ className="flex items-center gap-2"
321
+ >
322
+ <Eye className="h-4 w-4" />
323
+ Preview
324
+ </TabsTrigger>
325
+
326
+ <TabsTrigger
327
+ value="code"
328
+ className="flex items-center gap-1"
329
+ >
330
+ <Code className="h-4 w-4" />
331
+ Code
332
+ </TabsTrigger>
333
+ </TabsList>
334
+
335
+ <div className="flex items-center gap-1">
336
+ <Button
337
+ variant="outline"
338
+ size="sm"
339
+ onClick={() =>
340
+ handleCopyCode(
341
+ messages[messages.length - 1].content
342
+ )
343
+ }
344
+ >
345
+ <Copy className="h-4 w-4 mr-2" />
346
+ Copy
347
+ </Button>
348
+
349
+ <Button
350
+ variant="outline"
351
+ size="sm"
352
+ onClick={() =>
353
+ handleDownloadCode(
354
+ messages[messages.length - 1].content,
355
+ `code-${messages[messages.length - 1].id}.tsx`
356
+ )
357
+ }
358
+ >
359
+ <Download className="h-4 w-4 mr-2" />
360
+ Download
361
+ </Button>
362
+
363
+ <Button
364
+ variant="ghost"
365
+ size="icon"
366
+ onClick={toggleFullscreen}
367
+ >
368
+ {previewState.isFullscreen ? (
369
+ <Minimize2 className="h-4 w-4" />
370
+ ) : (
371
+ <Maximize2 className="h-4 w-4" />
372
+ )}
373
+ </Button>
374
+
375
+ <Button
376
+ variant="ghost"
377
+ size="icon"
378
+ onClick={() =>
379
+ setPreviewState((prev) => ({
380
+ ...prev,
381
+ isOpen: false,
382
+ }))
383
+ }
384
+ >
385
+ <X className="h-4 w-4" />
386
+ </Button>
387
+ </div>
388
+ </div>
389
+
390
+ <TabsContent
391
+ value="preview"
392
+ className="flex-1 overflow-auto"
393
+ >
394
+ <ScrollArea className="h-full">
395
+ <div className="p-4">
396
+ <DynamicFileRenderer
397
+ id={messages[messages.length - 1].id}
398
+ />
399
+ </div>
400
+ </ScrollArea>
401
+ </TabsContent>
402
+
403
+ <TabsContent
404
+ value="code"
405
+ className="flex-1 overflow-auto"
406
+ >
407
+ <ScrollArea className="h-full">
408
+ <div className="p-4">
409
+ <SyntaxHighlighter
410
+ language="typescript"
411
+ style={isDark ? customOneDark : customOneLight}
412
+ className="!m-0 !bg-transparent"
413
+ >
414
+ {messages[messages.length - 1].content}
415
+ </SyntaxHighlighter>
416
+ </div>
417
+ </ScrollArea>
418
+ </TabsContent>
419
+ </Tabs>
420
+ </div>
421
+ </ResizablePanel>
422
+ </>
423
+ )}
424
+ </ResizablePanelGroup>
425
+ )}
426
  </div>
427
  </div>
428
  );