feat(navbar): make delete & plus button work

This commit is contained in:
ItzCrazyKns 2024-10-29 19:59:58 +05:30
parent dfb532e4d3
commit 03d0ff2ca4
3 changed files with 27 additions and 8 deletions

View file

@ -11,19 +11,24 @@ import {
import { Fragment, useState } from 'react';
import { toast } from 'sonner';
import { Chat } from '@/app/library/page';
import { useRouter } from 'next/navigation';
const DeleteChat = ({
chatId,
chats,
setChats,
redirect = false,
}: {
chatId: string;
chats: Chat[];
setChats: (chats: Chat[]) => void;
redirect?: boolean;
}) => {
const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false);
const [loading, setLoading] = useState(false);
const router = useRouter();
const handleDelete = async () => {
setLoading(true);
try {
@ -44,6 +49,10 @@ const DeleteChat = ({
const newChats = chats.filter((chat) => chat.id !== chatId);
setChats(newChats);
if (redirect) {
router.push('/');
}
} catch (err: any) {
toast.error(err.message);
} finally {