diff --git a/src/app/(route)/chat/ChatPage.tsx b/src/app/(route)/chat/ChatPage.tsx index 6569c3f2..c54964ea 100644 --- a/src/app/(route)/chat/ChatPage.tsx +++ b/src/app/(route)/chat/ChatPage.tsx @@ -1,13 +1,192 @@ 'use client'; -import QueryBox from '@/app/(route)/home/_components/HomeQueryBox/HomeQueryBox'; +import HomeQueryBox from '@/app/(route)/home/_components/HomeQueryBox/HomeQueryBox'; +import CardList from '@/components/basics/CardList/CardList'; +import LinkCard from '@/components/basics/LinkCard/LinkCard'; +import Tab from '@/components/basics/Tab/Tab'; +import UserChatBox from '@/components/wrappers/UserChatBox/UserChatBox'; +import { chatHistoryById, chatLinksById, chatReasoningById, mockChats } from '@/mocks'; +import { useChatRightPanelStore } from '@/stores/chatRightPanelStore'; +import { useChatStore } from '@/stores/chatStore'; +import { useSearchParams } from 'next/navigation'; +import { useEffect, useMemo, useState } from 'react'; export default function Chat() { + const params = useSearchParams(); + const { setChats, setActiveChat } = useChatStore(); + const { setSelectedLink } = useChatRightPanelStore(); + const [message, setMessage] = useState(''); + const useMockData = process.env.NEXT_PUBLIC_USE_MOCKS === 'true'; + + const activeId = useMemo(() => { + const param = params.get('chatId'); + const parsed = param ? Number(param) : NaN; + if (!Number.isNaN(parsed)) return parsed; + return useMockData ? (mockChats[0]?.id ?? null) : null; + }, [params, useMockData]); + + useEffect(() => { + setChats(useMockData ? mockChats : []); + }, [setChats, useMockData]); + + useEffect(() => { + if (activeId !== null) { + setActiveChat(activeId); + } + }, [activeId, setActiveChat]); + + const messages = useMemo(() => { + if (!useMockData || activeId === null) return []; + return chatHistoryById[activeId] ?? []; + }, [activeId, useMockData]); + const chatPairs = useMemo(() => { + const pairs: { + user: (typeof messages)[number]; + assistant?: (typeof messages)[number]; + }[] = []; + let pendingUser: (typeof messages)[number] | null = null; + + messages.forEach(message => { + if (message.role === 'user') { + if (pendingUser) { + pairs.push({ user: pendingUser }); + } + pendingUser = message; + } else if (message.role === 'assistant') { + if (pendingUser) { + pairs.push({ user: pendingUser, assistant: message }); + pendingUser = null; + } + } + }); + + if (pendingUser) { + pairs.push({ user: pendingUser }); + } + + return pairs; + }, [messages]); + const linkCards = activeId && useMockData ? (chatLinksById[activeId] ?? []) : []; + const reasoning = activeId && useMockData ? chatReasoningById[activeId] : undefined; return ( -
요청을 입력해 보세요.
+ ) : ( ++ {reasoning?.answer ?? assistant?.content ?? '응답을 생성 중입니다.'} +
+표시할 링크가 없습니다.
+ ) : ( +표시할 링크가 없습니다.
+ ) : ( ++ {index + 1}. {step.step} +
+ {relatedLinks.length > 0 && ( +