"use client"; import * as React from "react"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogTrigger, } from "@radix-ui/react-dialog"; import { TrashIcon } from "@radix-ui/react-icons"; import { useRouter } from "next/navigation"; import { useHasMounted } from "@/lib/utils"; import { DialogHeader } from "./ui/dialog"; export default function ClearChatsButton() { const hasMounted = useHasMounted(); const router = useRouter(); if (!hasMounted) { return null; } const chats = Object.keys(localStorage).filter((key) => key.startsWith("chat_") ); const disabled = chats.length === 0; const clearChats = () => { chats.forEach((key) => { localStorage.removeItem(key); }); window.dispatchEvent(new Event("storage")); router.push("/"); }; return ( Clear chats Are you sure you want to delete all chats? This action cannot be undone.
Cancel clearChats()} > Delete
); }