import React, { useEffect, useState } from 'react'; import { ViewConfig } from '../../App'; import { MessageSquare, Loader, AlertCircle, Calendar, ChevronRight, Folder } from 'lucide-react'; import { fetchSessions, type Session } from '../../sessions'; import { Card } from '../ui/card'; import { Button } from '../ui/button'; import BackButton from '../ui/BackButton'; import { ScrollArea } from '../ui/scroll-area'; interface SessionListViewProps { setView: (view: ViewConfig['view'], viewOptions?: Record) => void; onSelectSession: (sessionId: string) => void; } const SessionListView: React.FC = ({ setView, onSelectSession }) => { const [sessions, setSessions] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { // Load sessions on component mount loadSessions(); }, []); const loadSessions = async () => { setIsLoading(true); setError(null); try { const response = await fetchSessions(); setSessions(response.sessions); } catch (err) { console.error('Failed to load sessions:', err); setError('Failed to load sessions. Please try again later.'); setSessions([]); } finally { setIsLoading(false); } }; // Format date to be more readable // eg. "10:39 PM, Feb 28, 2025" const formatDate = (dateString: string) => { try { const date = new Date(dateString); const time = new Intl.DateTimeFormat('en-US', { hour: 'numeric', minute: 'numeric', hour12: true, }).format(date); const dateStr = new Intl.DateTimeFormat('en-US', { month: 'short', day: 'numeric', year: 'numeric', }).format(date); return `${time}, ${dateStr}`; } catch (e) { return dateString; } }; return (
setView('chat')} />
{/* Content Area */}

Previous goose sessions

View previous goose sessions and their contents to pick up where you left off.

{isLoading ? (
) : error ? (

Error Loading Sessions

{error}

) : sessions.length > 0 ? (
{sessions.map((session) => ( onSelectSession(session.id)} className="p-2 bg-bgSecondary hover:bg-bgSubtle cursor-pointer transition-all duration-150" >

{session.metadata.description || session.id}

{formatDate(session.modified)}
{session.metadata.working_dir}
{session.path.split('/').pop() || session.path}
{session.metadata.message_count}
{session.metadata.total_tokens !== null && (
{session.metadata.total_tokens.toLocaleString()} tokens
)}
))}
) : (

No chat sessions found

Your chat history will appear here

)}
); }; export default SessionListView;