import React from 'react'; import { useSessionStore } from '@openchamber/ui/stores/useSessionStore'; import { useNavigation } from '../hooks/useNavigation'; import { VSCodeHeader } from './VSCodeHeader'; import { SessionItem } from './SessionItem'; export function SessionsListView() { const { sessions, currentSessionId, setCurrentSession, createSession, streamingMessageIds } = useSessionStore(); const { goToChat } = useNavigation(); const [isCreating, setIsCreating] = React.useState(false); const sortedSessions = React.useMemo(() => { return [...sessions].sort((a, b) => (b.time?.created || 0) - (a.time?.created || 0)); }, [sessions]); const handleSelectSession = async (sessionId: string) => { await setCurrentSession(sessionId); goToChat(); }; const handleNewSession = async () => { if (isCreating) return; setIsCreating(true); try { await createSession(); goToChat(); } catch (error) { console.error('Failed to create session:', error); } finally { setIsCreating(false); } }; const newButton = ( ); return (
{sortedSessions.length === 0 ? (
No sessions yet
) : (
{sortedSessions.map((session) => ( handleSelectSession(session.id)} /> ))}
)}
); }