import { useChatHandler } from "@/components/chat/chat-hooks/use-chat-handler" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog" import { ChatbotUIContext } from "@/context/context" import { deleteChat } from "@/db/chats" import useHotkey from "@/lib/hooks/use-hotkey" import { Tables } from "@/supabase/types" import { IconTrash } from "@tabler/icons-react" import { FC, useContext, useRef, useState } from "react" interface DeleteChatProps { chat: Tables<"chats"> } export const DeleteChat: FC = ({ chat }) => { useHotkey("Backspace", () => setShowChatDialog(true)) const { setChats } = useContext(ChatbotUIContext) const { handleNewChat } = useChatHandler() const buttonRef = useRef(null) const [showChatDialog, setShowChatDialog] = useState(false) const handleDeleteChat = async () => { await deleteChat(chat.id) setChats(prevState => prevState.filter(c => c.id !== chat.id)) setShowChatDialog(false) handleNewChat() } const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter") { buttonRef.current?.click() } } return ( Delete {chat.name} Are you sure you want to delete this chat? ) }