diff --git a/frontend/src/app/[locale]/(protect)/chat/components/chat-arena/chat-arena-index.tsx b/frontend/src/app/[locale]/(protect)/chat/components/chat-arena/chat-arena-index.tsx index e458ac6..f7d8247 100644 --- a/frontend/src/app/[locale]/(protect)/chat/components/chat-arena/chat-arena-index.tsx +++ b/frontend/src/app/[locale]/(protect)/chat/components/chat-arena/chat-arena-index.tsx @@ -2,7 +2,7 @@ import { useState } from 'react'; -import { useParams, useSearchParams } from 'next/navigation'; +import { useParams, useRouter, useSearchParams } from 'next/navigation'; import useCreate from '@/hooks/use-create'; import useQuery from '@/hooks/use-query'; @@ -22,6 +22,7 @@ interface ChatSubmitOptions { type ChatSubmitHandler = (event?: ChatSubmitEvent, options?: ChatSubmitOptions) => void; export default function ChatIndex() { + const router = useRouter(); const [messages, setMessages] = useState([]); const [input, setInput] = useState(''); const [isGenerating, setIsGenerating] = useState(false); @@ -54,6 +55,7 @@ export default function ChatIndex() { 'chat', query ); + // router.push(`/chat/${param.id}?projectId=${projectId}`); } const newMessages = [...messages, userMessage]; diff --git a/frontend/src/app/[locale]/(protect)/chat/components/chat-arena/header-chat.tsx b/frontend/src/app/[locale]/(protect)/chat/components/chat-arena/header-chat.tsx index 3133a81..8f0ffc9 100644 --- a/frontend/src/app/[locale]/(protect)/chat/components/chat-arena/header-chat.tsx +++ b/frontend/src/app/[locale]/(protect)/chat/components/chat-arena/header-chat.tsx @@ -3,13 +3,12 @@ import { useParams } from 'next/navigation'; import useGet from '@/hooks/use-get'; +import { useListChatStore } from '@/store/chat-list.store'; export default function HeaderChat() { + const { selectedChat, setSelectedChat } = useListChatStore(); const param: { id: string[] } = useParams(); - let chat: any = null; - if (param.id) { - chat = useGet('chat-sessions', param.id); - } + useGet('chat-sessions', param.id, setSelectedChat); - return
{chat?.title}
; + return
{selectedChat?.title}
; } diff --git a/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/document-header.tsx b/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/document-header.tsx deleted file mode 100644 index b513dc5..0000000 --- a/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/document-header.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuLabel, - DropdownMenuSeparator, - DropdownMenuShortcut, - DropdownMenuTrigger -} from '@/registry/new-york-v4/ui/dropdown-menu'; -import { SidebarMenu, SidebarMenuButton, SidebarMenuItem } from '@/registry/new-york-v4/ui/sidebar'; - -import { FileText } from 'lucide-react'; - -export default function DocumentHeader() { - return ( - - - -
- -
-
-

Tài Liệu

-
-
-
-
- ); -} diff --git a/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/dropdown-menu.jsx b/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/dropdown-menu.jsx deleted file mode 100644 index 065c7fa..0000000 --- a/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/dropdown-menu.jsx +++ /dev/null @@ -1,57 +0,0 @@ -'use client'; - -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuGroup, - DropdownMenuItem, - DropdownMenuLabel, - DropdownMenuPortal, - DropdownMenuSeparator, - DropdownMenuShortcut, - DropdownMenuSub, - DropdownMenuSubContent, - DropdownMenuSubTrigger, - DropdownMenuTrigger -} from '@/registry/new-york-v4/ui/dropdown-menu'; - -//icon -import { BookOpen, EllipsisVertical, FilePen, Trash2 } from 'lucide-react'; - -export function DropdownMenuNav({ setIsDropDownOpen, isDropDownOpen, setShowControls }) { - function handleClick(e) { - e.stopPropagation(); - setIsDropDownOpen((open) => !open); - } - - const handleOpenChange = (open) => { - setIsDropDownOpen(open); - if (!open) { - setShowControls(false); - } - }; - - return ( - - - - - - - View - - - - Update - - - - Delete - - - - - ); -} diff --git a/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/file-list-item.jsx b/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/file-list-item.jsx index 9b5534a..8256a05 100644 --- a/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/file-list-item.jsx +++ b/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/file-list-item.jsx @@ -11,19 +11,31 @@ export function FileItem({ file }) { setOpen(!open); } + function handleClickMoveOut() { + console.log(window); + } + return ( -
+
-
{file.type}
+ className={`flex h-full w-full flex-1/2 items-center rounded-l-lg ${file.type === 'pdf' ? 'bg-orange-400' : 'bg-blue-500'} p-3`}> +
+ {file.type} +
-
- - - +
+
+ +
+
+ +
+
+ +
+ className={`absolute left-0 z-50 flex h-full w-[88%] justify-between gap-1 rounded-lg bg-white px-2 ${open ? '-translate-x-0.5' : 'translate-x-7.5'} transition-all`}>

{file.name}

{file.size}

diff --git a/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/file-list.tsx b/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/file-list.tsx index cd6712d..6ddb11a 100644 --- a/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/file-list.tsx +++ b/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-document-right/file-list.tsx @@ -5,6 +5,7 @@ import { useState } from 'react'; import { Checkbox } from '@/registry/new-york-v4/ui/checkbox'; import { FileItem } from './file-list-item'; +import { Trash2 } from 'lucide-react'; // Mock data cho danh sách file const mockFiles = [ @@ -21,13 +22,21 @@ const mockFiles = [ ]; export function FileList() { + const [selectAll, setSelectAll] = useState(false); + return (
Library -
- - +
+
+ +
+ setSelectAll(!selectAll)} + className='h-5 w-5 border-stone-500 ring-stone-500 data-[state=checked]:border-stone-500' + />
diff --git a/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-function-left/chat-list.tsx b/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-function-left/chat-list.tsx index c956a82..fcc6d8d 100644 --- a/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-function-left/chat-list.tsx +++ b/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-function-left/chat-list.tsx @@ -178,6 +178,9 @@ export function ChatList() { ))} +
+
New Chat
+
); } diff --git a/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-function-left/project-switcher.tsx b/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-function-left/project-switcher.tsx index b548893..143fcfe 100644 --- a/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-function-left/project-switcher.tsx +++ b/frontend/src/app/[locale]/(protect)/chat/components/sidebar/sidebar-function-left/project-switcher.tsx @@ -1,28 +1,22 @@ 'use client'; -import { useEffect, useState } from 'react'; +import { useState } from 'react'; import { useRouter, useSearchParams } from 'next/navigation'; -import { CreateProjectAPI, GetAllProjectsAPI } from '@/app/api/client/project-list.api'; -import { ProjectDialogContent } from '@/components/project-dialog'; -import { Dialog, DialogTrigger } from '@/registry/new-york-v4/ui/dialog'; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuLabel, - DropdownMenuSeparator, - DropdownMenuShortcut, - DropdownMenuTrigger -} from '@/registry/new-york-v4/ui/dropdown-menu'; -import { SidebarMenu, SidebarMenuButton, SidebarMenuItem, useSidebar } from '@/registry/new-york-v4/ui/sidebar'; -import { Skeleton } from '@/registry/new-york-v4/ui/skeleton'; +import { description } from '@/components/demo/chart-area-demo'; +import useCreate from '@/hooks/use-create'; +import useGet from '@/hooks/use-get'; +import { parseData } from '@/hooks/use-gets'; +import { Button } from '@/registry/new-york-v4/ui/button'; +import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/registry/new-york-v4/ui/collapsible'; +import { Input } from '@/registry/new-york-v4/ui/input'; +import { Label } from '@/registry/new-york-v4/ui/label'; +import { Textarea } from '@/registry/new-york-v4/ui/textarea'; import { ProjectType } from '@/schemas/project-list.schemas'; import { useListProjectStore } from '@/store/project-list.store'; -import { Briefcase, ChevronsUpDown, Plus } from 'lucide-react'; -import { toast } from 'sonner'; +import { ChevronsUpDown } from 'lucide-react'; export function ProjectSwitcher() { const router = useRouter(); @@ -31,52 +25,27 @@ export function ProjectSwitcher() { const { projects, selectedProject, setSelectedProject, setProjects } = useListProjectStore(); const [isLoading, setIsLoading] = useState(false); const [isOpen, setIsOpen] = useState(false); + const [isCreate, setIsCreate] = useState(false); const projectId = searchParams.get('projectId'); - useEffect(() => { - setIsLoading(true); - if (!projectId) { - router.push('/dashboard'); - - return; - } - - if (selectedProject?.id === projectId) { - setIsLoading(false); - - return; - } - - const fetchProjects = async () => { - const response = await GetAllProjectsAPI(); - if (response.success) { - setProjects(response.data); - const project = response.data.find((p: ProjectType) => p.id === projectId); - if (project) { - setSelectedProject(project); - setIsLoading(false); - toast.success('Success', { - description: 'Project fetch success', - duration: 2000 - }); - - return; - } else { - toast.error('Error', { - description: 'This project was not found.', - duration: 2000 - }); - } - } - toast.error('Error', { - description: response.error?.message, - duration: 2000 - }); - router.push('/dashboard'); - }; + if (!projectId) { + router.push('/dashboard'); + } + useGet('projects', projectId, setSelectedProject); + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + const formData = new FormData(e.currentTarget); + handleCreateProject({ + name: formData.get('name') as string, + description: formData.get('description') as string + }); + }; - fetchProjects(); - }, []); + const handleCreateProject = async (data: { name: string; description: string }) => { + setIsLoading(true); + await useCreate('projects', data, projects, setProjects, 'project', null); + }; const handleProjectClick = (project: ProjectType) => { if (project.id !== selectedProject?.id) { @@ -85,113 +54,50 @@ export function ProjectSwitcher() { } }; - const handleCreateProject = async (data: { name: string; description: string }) => { - setIsLoading(true); - const response = await CreateProjectAPI({ - title: data.name, - description: data.description - }); - - if (response.success) { - setProjects([...projects, response.data]); - setSelectedProject(response.data); - setIsOpen(false); - router.push(`/chat/?projectId=${response.data.id}`); - toast.success('Success', { - description: 'Project created successfully', - duration: 2000 - }); - } else { - toast.error('Error', { - description: response.error?.message || 'Failed to create project', - duration: 2000 - }); - } - setIsLoading(false); - }; - return ( - - - - - - {isLoading ? ( -
-
- -
-
- - -
- -
- ) : ( - <> -
- -
-
- {selectedProject?.title || ''} - {selectedProject?.description || ''} -
- - - )} -
-
- - Dự án - {isLoading ? ( - Array(3) - .fill(0) - .map((_, i) => ( -
- -
- )) - ) : ( - <> - {projects.map((project, index) => ( - handleProjectClick(project)}> - {project.title} - ⌘{index + 1} - - ))} - - - -
-
- -
-
Thêm dự án
-
-
- -
- - )} -
-
-
-
+ +
+

Select Project

+ + + +
+
+ {selectedProject?.name} +
+ + {projects.map((item: ProjectType) => ( +
handleProjectClick(item)} + className='cursor-pointer px-4 py-2 font-mono text-sm'> + {item.name} +
+ ))} +
+
+
setIsCreate(!isCreate)} + className={`w-full rounded-lg ${isCreate && 'border-b border-dashed'} cursor-pointer border-gray-500 p-2 text-center`}> + New Project +
+ {isCreate && ( +
+
+ + +
+ +
+ +