Remove connected rows when removing chat (#490)
This commit is contained in:
parent
4880e0d94e
commit
fe3d58fc65
2 changed files with 5 additions and 5 deletions
|
|
@ -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('/');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue