From 83a86204629547aac3a249ffa15bc52b6ce2c9fe Mon Sep 17 00:00:00 2001 From: Alessandro Dal Grande Date: Wed, 25 Sep 2024 18:10:03 -0700 Subject: [PATCH] Transition to single chat url once the first answer is delivered --- ui/components/ChatWindow.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index b3d0089..480b5a9 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -10,6 +10,7 @@ import { toast } from 'sonner'; import { useSearchParams } from 'next/navigation'; import { getSuggestions } from '@/lib/actions'; import Error from 'next/error'; +import { useRouter } from 'next/navigation'; export type Message = { messageId: string; @@ -283,6 +284,8 @@ const ChatWindow = ({ id }: { id?: string }) => { const [notFound, setNotFound] = useState(false); + const router = useRouter(); + useEffect(() => { if ( chatId && @@ -420,6 +423,11 @@ const ChatWindow = ({ id }: { id?: string }) => { } if (data.type === 'messageEnd') { + if (!chatHistory.length) { + const url = `/c/${chatId}`; + router.replace(url); + } + setChatHistory((prevHistory) => [ ...prevHistory, ['human', message],