From f45bfac32b0908e8ea777ba0b3565919998877b5 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 5 Nov 2024 23:25:26 +0300 Subject: [PATCH] Push route state on generation finish (#492) --- components/custom/chat.tsx | 3 +++ components/custom/message.tsx | 7 ++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/custom/chat.tsx b/components/custom/chat.tsx index 041827a..a091af4 100644 --- a/components/custom/chat.tsx +++ b/components/custom/chat.tsx @@ -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; 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}`); }, }); diff --git a/components/custom/message.tsx b/components/custom/message.tsx index 9934c72..3e47a73 100644 --- a/components/custom/message.tsx +++ b/components/custom/message.tsx @@ -2,7 +2,6 @@ import { Message } from 'ai'; import cx from 'classnames'; -import { motion } from 'framer-motion'; import { Sparkles } from 'lucide-react'; import { Dispatch, SetStateAction } from 'react'; @@ -31,10 +30,8 @@ export const PreviewMessage = ({ isLoading: boolean; }) => { return ( -
-
+ ); };