Refresh router when creating and deleting chats (#34)

This commit is contained in:
Steven Tey 2023-06-17 13:15:42 -05:00 committed by GitHub
commit 10c9d8ba4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

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

View file

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