Transition to single chat url once the first answer is delivered

This commit is contained in:
Alessandro Dal Grande 2024-09-25 18:10:03 -07:00
parent d85d9f164b
commit 83a8620462
No known key found for this signature in database
GPG key ID: 1525AA5896744CF2

View file

@ -10,6 +10,7 @@ import { toast } from 'sonner';
import { useSearchParams } from 'next/navigation'; import { useSearchParams } from 'next/navigation';
import { getSuggestions } from '@/lib/actions'; import { getSuggestions } from '@/lib/actions';
import Error from 'next/error'; import Error from 'next/error';
import { useRouter } from 'next/navigation';
export type Message = { export type Message = {
messageId: string; messageId: string;
@ -283,6 +284,8 @@ const ChatWindow = ({ id }: { id?: string }) => {
const [notFound, setNotFound] = useState(false); const [notFound, setNotFound] = useState(false);
const router = useRouter();
useEffect(() => { useEffect(() => {
if ( if (
chatId && chatId &&
@ -420,6 +423,11 @@ const ChatWindow = ({ id }: { id?: string }) => {
} }
if (data.type === 'messageEnd') { if (data.type === 'messageEnd') {
if (!chatHistory.length) {
const url = `/c/${chatId}`;
router.replace(url);
}
setChatHistory((prevHistory) => [ setChatHistory((prevHistory) => [
...prevHistory, ...prevHistory,
['human', message], ['human', message],