import { TrashIcon } from 'lucide-react'; import { Description, Dialog, DialogBackdrop, DialogPanel, DialogTitle, Transition, TransitionChild, } from '@headlessui/react'; import { Fragment, useState } from 'react'; import { toast } from 'sonner'; import { Chat } from '@/app/library/page'; import { useRouter } from 'next/navigation'; import { getApiUrl, del } from '@/lib/api'; 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 { await del(getApiUrl(`/chats/${chatId}`)); // 从列表中移除聊天 setChats(chats.filter((chat) => chat.id !== chatId)); if (redirect) { router.push('/'); } toast.success('聊天已删除'); } catch (error) { console.error('删除聊天失败:', error); toast.error('删除聊天失败'); } finally { setLoading(false); setConfirmationDialogOpen(false); } }; return ( <> { if (!loading) { setConfirmationDialogOpen(false); } }} >
Delete Confirmation Are you sure you want to delete this chat?
); }; export default DeleteChat;