diff --git a/components/custom/sidebar-history.tsx b/components/custom/sidebar-history.tsx index 8217aa6..cb6e01f 100644 --- a/components/custom/sidebar-history.tsx +++ b/components/custom/sidebar-history.tsx @@ -8,11 +8,7 @@ import { useEffect, useState } from 'react'; import { toast } from 'sonner'; import useSWR from 'swr'; -import { - InfoIcon, - MoreHorizontalIcon, - TrashIcon, -} from '@/components/custom/icons'; +import { MoreHorizontalIcon, TrashIcon } from '@/components/custom/icons'; import { AlertDialog, AlertDialogAction, @@ -127,6 +123,7 @@ export function SidebarHistory({ user }: { user: User | undefined }) { }); setShowDeleteDialog(false); + if (deleteId === id) { router.push('/'); } diff --git a/db/queries.ts b/db/queries.ts index 5772c0c..2315800 100644 --- a/db/queries.ts +++ b/db/queries.ts @@ -67,6 +67,9 @@ export async function saveChat({ export async function deleteChatById({ id }: { id: string }) { try { + await db.delete(vote).where(eq(vote.chatId, id)); + await db.delete(message).where(eq(message.chatId, id)); + return await db.delete(chat).where(eq(chat.id, id)); } catch (error) { console.error('Failed to delete chat by id from database');