From 5c3001e29a571d1eea6cf0d3dbd779d1e5cfe361 Mon Sep 17 00:00:00 2001 From: Gary Meehan Date: Wed, 4 Oct 2023 22:27:23 +0100 Subject: [PATCH] add redirect --- components/chat.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/chat.tsx b/components/chat.tsx index a9ecafe..a4c60cc 100644 --- a/components/chat.tsx +++ b/components/chat.tsx @@ -20,6 +20,7 @@ import { useState } from 'react' import { Button } from './ui/button' import { Input } from './ui/input' import { toast } from 'react-hot-toast' +import { usePathname, useRouter } from 'next/navigation' const IS_PREVIEW = process.env.VERCEL_ENV === 'preview' export interface ChatProps extends React.ComponentProps<'div'> { @@ -28,6 +29,8 @@ export interface ChatProps extends React.ComponentProps<'div'> { } export function Chat({ id, initialMessages, className }: ChatProps) { + const router = useRouter() + const path = usePathname() const [previewToken, setPreviewToken] = useLocalStorage( 'ai-token', null @@ -46,6 +49,12 @@ export function Chat({ id, initialMessages, className }: ChatProps) { if (response.status === 401) { toast.error(response.statusText) } + }, + onFinish() { + if (!path.includes('chat')) { + router.push(`/chat/${id}`, { shallow: true }) + router.refresh() + } } }) return (