import { useEffect, useState } from 'react'; import { classNames } from '../utils/misc'; import { Conversation } from '../utils/types'; import StorageUtils from '../utils/storage'; import { useNavigate, useParams } from 'react-router'; export default function Sidebar() { const params = useParams(); const navigate = useNavigate(); const [conversations, setConversations] = useState([]); const [currConv, setCurrConv] = useState(null); useEffect(() => { StorageUtils.getOneConversation(params.convId ?? '').then(setCurrConv); }, [params.convId]); useEffect(() => { const handleConversationChange = async () => { setConversations(await StorageUtils.getAllConversations()); }; StorageUtils.onConversationChanged(handleConversationChange); handleConversationChange(); return () => { StorageUtils.offConversationChanged(handleConversationChange); }; }, []); return ( <>

Conversations

{/* close sidebar button */}
{/* list of conversations */}
navigate('/')} > + New conversation
{conversations.map((conv) => (
navigate(`/chat/${conv.id}`)} dir="auto" > {conv.name}
))}
Conversations are saved to browser's IndexedDB
); }