Push route state on generation finish (#492)

This commit is contained in:
Jeremy 2024-11-05 23:25:26 +03:00 committed by GitHub
parent 5d6d0ed664
commit f45bfac32b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 5 deletions

View file

@ -3,6 +3,7 @@
import { Attachment, Message } from 'ai';
import { useChat } from 'ai/react';
import { AnimatePresence } from 'framer-motion';
import { useRouter } from 'next/navigation';
import { useState } from 'react';
import useSWR, { useSWRConfig } from 'swr';
import { useWindowSize } from 'usehooks-ts';
@ -27,6 +28,7 @@ export function Chat({
initialMessages: Array<Message>;
selectedModelId: string;
}) {
const router = useRouter();
const { mutate } = useSWRConfig();
const {
@ -44,6 +46,7 @@ export function Chat({
initialMessages,
onFinish: () => {
mutate('/api/history');
router.push(`/chat/${id}`);
},
});