import { Fragment, useEffect, useState, useRef, useCallback } from 'react'; import { toast } from 'react-toastify'; import { motion, type Variants } from 'framer-motion'; import { cubicEasingFn } from '~/utils/easings'; import { db, getAll, type ChatHistory } from '~/lib/persistence'; import { HistoryItem } from './HistoryItem'; import { binDates } from './date-binning'; const menuVariants = { closed: { left: '-400px', transition: { duration: 0.2, ease: cubicEasingFn, }, }, open: { left: 0, transition: { duration: 0.2, ease: cubicEasingFn, }, }, } satisfies Variants; export function Menu() { const menuRef = useRef(null); const [list, setList] = useState([]); const [open, setOpen] = useState(false); const loadEntries = useCallback(() => { if (db) { getAll(db) .then((list) => list.filter((item) => item.urlId && item.description)) .then(setList) .catch((error) => toast.error(error.message)); } }, []); useEffect(() => { if (open) { loadEntries(); } }, [open]); useEffect(() => { function onMouseMove(event: MouseEvent) { if (event.pageX < 80) { setOpen(true); } } function onMouseLeave(_event: MouseEvent) { setOpen(false); } menuRef.current?.addEventListener('mouseleave', onMouseLeave); window.addEventListener('mousemove', onMouseMove); return () => { menuRef.current?.removeEventListener('mouseleave', onMouseLeave); window.removeEventListener('mousemove', onMouseMove); }; }, []); return (
Bolt
Start new chat
Your Chats
{list.length === 0 &&
No previous conversations
} {binDates(list).map(({ category, items }) => (
{category}
{items.map((item) => ( ))}
))}
); }