"use client"; import Link from "next/link"; import { useRouter } from "next/navigation"; import type { User } from "next-auth"; import { useState } from "react"; import { toast } from "sonner"; import { useSWRConfig } from "swr"; import { unstable_serialize } from "swr/infinite"; import { PlusIcon, TrashIcon } from "@/components/icons"; import { getChatHistoryPaginationKey, SidebarHistory, } from "@/components/sidebar-history"; import { SidebarUserNav } from "@/components/sidebar-user-nav"; import { Button } from "@/components/ui/button"; import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarMenu, useSidebar, } from "@/components/ui/sidebar"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "./ui/alert-dialog"; import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip"; export function AppSidebar({ user }: { user: User | undefined }) { const router = useRouter(); const { setOpenMobile } = useSidebar(); const { mutate } = useSWRConfig(); const [showDeleteAllDialog, setShowDeleteAllDialog] = useState(false); const handleDeleteAll = () => { const deletePromise = fetch("/api/history", { method: "DELETE", }); toast.promise(deletePromise, { loading: "正在删除所有会话...", success: () => { mutate(unstable_serialize(getChatHistoryPaginationKey)); router.push("/"); setShowDeleteAllDialog(false); return "所有会话已删除"; }, error: "删除会话失败,请稍后重试", }); }; return ( <>
{/* Logo removed */}
{user && ( 删除所有会话 )} 新建会话
{user && } 确定删除全部会话? 操作不可撤销,所有会话记录将从服务器永久移除。 取消 删除所有 ); }