From ef950108c5d8c418512ebdc9a646eb9468288596 Mon Sep 17 00:00:00 2001 From: Rohit Date: Wed, 5 Mar 2025 01:24:22 +0530 Subject: [PATCH 1/4] Enhance ProjectsDrawer with search functionality and user authentication checks, also added scroll-area to chat and improved Chat-UI, associated actions to prompts --- .../frontend/app/project/[projectId]/page.tsx | 193 ++++++++++++------ .../frontend/components/ProjectsDrawer.tsx | 107 ++++++---- .../apps/frontend/components/Prompt.tsx | 7 +- .../frontend/components/ui/scroll-area.tsx | 58 ++++++ 4 files changed, 263 insertions(+), 102 deletions(-) create mode 100644 mobile-magic/apps/frontend/components/ui/scroll-area.tsx diff --git a/mobile-magic/apps/frontend/app/project/[projectId]/page.tsx b/mobile-magic/apps/frontend/app/project/[projectId]/page.tsx index b8d4ac2..704e32f 100644 --- a/mobile-magic/apps/frontend/app/project/[projectId]/page.tsx +++ b/mobile-magic/apps/frontend/app/project/[projectId]/page.tsx @@ -1,86 +1,153 @@ "use client"; import { Button } from "@/components/ui/button"; -import { Input } from "@/components/ui/input"; + import { WORKER_URL } from "@/config"; -import { Send } from "lucide-react"; +import { Check, ClipboardCopy, Paperclip, Send } from "lucide-react"; import { usePrompts } from "@/hooks/usePrompts"; import { useActions } from "@/hooks/useActions"; import axios from "axios"; import { useState } from "react"; -import { useAuth, useUser } from "@clerk/nextjs"; +import { useAuth } from "@clerk/nextjs"; import { WORKER_API_URL } from "@/config"; -import { ProjectsDrawer } from "@/components/ProjectsDrawer"; -import Image from "next/image"; +import { ScrollArea } from "@/components/ui/scroll-area"; +import { Textarea } from "@/components/ui/textarea"; +interface Action { + id: string; + content?: string; + code?: string; +} export default function ProjectPage({ params }: { params: { projectId: string } }) { - const { prompts } = usePrompts(params.projectId); - const { actions } = useActions(params.projectId); + const prompts = [ + { id: '1', content: 'Show me a sample chart', type: 'USER' }, + { id: '2', content: 'Explain this data', type: 'USER' }, + ]; + + const actions: Action[] = [ + { + id: 'a1', + content: 'Here\'s your bar chart visualizing the data:', + code: 'chart.bar(data, x="category", y="values")' + }, + { + id: 'a2', + content: 'This data shows a clear trend in quarterly sales. The second quarter had the highest performance, with a 27% increase compared to Q1.', + code: 'data.describe()' + }, + ]; const [prompt, setPrompt] = useState(""); const { getToken } = useAuth(); - const {user} = useUser() + const [copied, setCopied] = useState(null); - const submitPrompt = async () => { - const token = await getToken(); - axios.post( - `${WORKER_API_URL}/prompt`, - { - projectId: params.projectId, - prompt: prompt, - }, - { - headers: { - Authorization: `Bearer ${token}`, - }, - }, - ); - setPrompt(""); - }; + const copyToClipboard = (text: string, id: string) => { + navigator.clipboard.writeText(text); + setCopied(id); + setTimeout(() => setCopied(null), 2000); + }; - return
-
-
-
- -
-
- {prompts.filter((prompt) => prompt.type === "USER").map((prompt) => ( - - Profile picture - {prompt.content} - + return ( +
+
+
+ Chat History +
+
+ +
+ {prompts.filter((prompt) => prompt.type === "USER").map((prompt, index) => ( +
+
+
+ U +
+
+
You
+
{prompt.content}
+
+
+ + {actions[index] && ( +
+
+ AI +
+
+
Assistant
+
{actions[index]?.content}
+ + {('code' in actions[index] && actions[index]?.code) && ( +
+
+ Code + +
+
+
+                                                                
+                                                                    {String(actions[index].code || "")}
+                                                                
+                                                            
+
+
+ )} +
+
+ )} +
))} -
- {actions.map((action) => ( -
- {action.content} -
- ))} +
+ +
+
+
+