Redirect to chat url and refresh sidebar data (#161)
This commit is contained in:
commit
4b0b529bc4
1 changed files with 9 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ 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 { toast } from 'react-hot-toast'
|
import { toast } from 'react-hot-toast'
|
||||||
|
import { usePathname, 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'> {
|
||||||
|
|
@ -28,6 +29,8 @@ 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 path = usePathname()
|
||||||
const [previewToken, setPreviewToken] = useLocalStorage<string | null>(
|
const [previewToken, setPreviewToken] = useLocalStorage<string | null>(
|
||||||
'ai-token',
|
'ai-token',
|
||||||
null
|
null
|
||||||
|
|
@ -46,6 +49,12 @@ export function Chat({ id, initialMessages, className }: ChatProps) {
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
toast.error(response.statusText)
|
toast.error(response.statusText)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
onFinish() {
|
||||||
|
if (!path.includes('chat')) {
|
||||||
|
router.push(`/chat/${id}`, { shallow: true })
|
||||||
|
router.refresh()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue