import { useEffect, useRef, useState } from "react"; import IconHistory from "virtual:icons/mdi/history"; import IconRestore from "virtual:icons/mdi/restore"; import { useChat } from "../composables"; import { __ } from "../utils/i18n"; import "./HistoryDropdown.scss"; export default function HistoryDropdown() { const { archivedConversations, clearArchivedConversations, restoreConversation, waitingForResponse, } = useChat(); const [isOpen, setIsOpen] = useState(false); const wrapperRef = useRef(null); useEffect(() => { if (!isOpen) { return; } const handleClick = (event: MouseEvent) => { if (!wrapperRef.current?.contains(event.target as Node)) { setIsOpen(false); } }; document.addEventListener("mousedown", handleClick); return () => document.removeEventListener("mousedown", handleClick); }, [isOpen]); if (archivedConversations.length === 0) { return null; } return (
{isOpen && (
{__("History", "flexible-chat")}
{archivedConversations.map((conversation) => ( ))}
)}
); }