Remove connected rows when removing chat (#490)

This commit is contained in:
Jeremy 2024-11-05 19:39:50 +03:00 committed by GitHub
parent 4880e0d94e
commit fe3d58fc65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 5 deletions

View file

@ -8,11 +8,7 @@ import { useEffect, useState } from 'react';
import { toast } from 'sonner'; import { toast } from 'sonner';
import useSWR from 'swr'; import useSWR from 'swr';
import { import { MoreHorizontalIcon, TrashIcon } from '@/components/custom/icons';
InfoIcon,
MoreHorizontalIcon,
TrashIcon,
} from '@/components/custom/icons';
import { import {
AlertDialog, AlertDialog,
AlertDialogAction, AlertDialogAction,
@ -127,6 +123,7 @@ export function SidebarHistory({ user }: { user: User | undefined }) {
}); });
setShowDeleteDialog(false); setShowDeleteDialog(false);
if (deleteId === id) { if (deleteId === id) {
router.push('/'); router.push('/');
} }

View file

@ -67,6 +67,9 @@ export async function saveChat({
export async function deleteChatById({ id }: { id: string }) { export async function deleteChatById({ id }: { id: string }) {
try { 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)); return await db.delete(chat).where(eq(chat.id, id));
} catch (error) { } catch (error) {
console.error('Failed to delete chat by id from database'); console.error('Failed to delete chat by id from database');