import { useEffect, useMemo, 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 currConv = useMemo( () => StorageUtils.getOneConversation(params.convId ?? ''), [params.convId] ); const [conversations, setConversations] = useState([]); useEffect(() => { const handleConversationChange = () => { setConversations(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.messages[0].content}
))}
Conversations are saved to browser's localStorage
); }