Refresh router when creating and deleting chats

This commit is contained in:
Steven Tey 2023-06-17 13:15:14 -05:00
parent 865899afad
commit 17efa26555
2 changed files with 7 additions and 0 deletions

View file

@ -19,6 +19,7 @@ import {
import { useState } from 'react' import { useState } from 'react'
import { Button } from './ui/button' import { Button } from './ui/button'
import { Input } from './ui/input' import { Input } from './ui/input'
import { useRouter } from 'next/navigation'
const IS_PREVIEW = process.env.VERCEL_ENV === 'preview' const IS_PREVIEW = process.env.VERCEL_ENV === 'preview'
export interface ChatProps extends React.ComponentProps<'div'> { export interface ChatProps extends React.ComponentProps<'div'> {
@ -27,6 +28,7 @@ export interface ChatProps extends React.ComponentProps<'div'> {
} }
export function Chat({ id, initialMessages, className }: ChatProps) { export function Chat({ id, initialMessages, className }: ChatProps) {
const router = useRouter()
const [previewToken, setPreviewToken] = useLocalStorage<string | null>( const [previewToken, setPreviewToken] = useLocalStorage<string | null>(
'ai-token', 'ai-token',
null null
@ -40,6 +42,9 @@ export function Chat({ id, initialMessages, className }: ChatProps) {
body: { body: {
id, id,
previewToken previewToken
},
onFinish: () => {
router.refresh()
} }
}) })
return ( return (

View file

@ -200,7 +200,9 @@ export function SidebarActions({
} }
setDeleteDialogOpen(false) setDeleteDialogOpen(false)
router.refresh()
router.push('/') router.push('/')
toast.success('Chat deleted')
}) })
}} }}
> >