Improve sidebar, new chat, and share dialog (#190)

This commit is contained in:
Jared Palmer 2023-12-04 12:42:53 -05:00 committed by GitHub
parent 35e83dc87e
commit be90a40427
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 598 additions and 217 deletions

View file

@ -20,10 +20,14 @@ import {
import { IconSpinner } from '@/components/ui/icons'
interface ClearHistoryProps {
isEnabled: boolean
clearChats: () => ServerActionResult<void>
}
export function ClearHistory({ clearChats }: ClearHistoryProps) {
export function ClearHistory({
isEnabled = false,
clearChats
}: ClearHistoryProps) {
const [open, setOpen] = React.useState(false)
const [isPending, startTransition] = React.useTransition()
const router = useRouter()
@ -31,7 +35,7 @@ export function ClearHistory({ clearChats }: ClearHistoryProps) {
return (
<AlertDialog open={open} onOpenChange={setOpen}>
<AlertDialogTrigger asChild>
<Button variant="ghost" disabled={isPending}>
<Button variant="ghost" disabled={!isEnabled || isPending}>
{isPending && <IconSpinner className="mr-2" />}
Clear history
</Button>
@ -50,16 +54,16 @@ export function ClearHistory({ clearChats }: ClearHistoryProps) {
disabled={isPending}
onClick={event => {
event.preventDefault()
startTransition(async () => {
const result = await clearChats()
startTransition(() => {
clearChats().then(result => {
if (result && 'error' in result) {
toast.error(result.error)
return
}
if (result && 'error' in result) {
toast.error(result.error)
return
}
setOpen(false)
router.push('/')
setOpen(false)
router.push('/')
})
})
}}
>