import React, { useState } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { FileText, ArrowLeft, Calendar, Clock, MessageSquare } from "lucide-react"; import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Pagination } from "@/components/ui/pagination"; import { ClaudeMemoriesDropdown } from "@/components/ClaudeMemoriesDropdown"; import { cn } from "@/lib/utils"; import { formatUnixTimestamp, formatISOTimestamp, truncateText, getFirstLine } from "@/lib/date-utils"; import type { Session, ClaudeMdFile } from "@/lib/api"; interface SessionListProps { /** * Array of sessions to display */ sessions: Session[]; /** * The current project path being viewed */ projectPath: string; /** * Callback to go back to project list */ onBack: () => void; /** * Callback when a session is clicked */ onSessionClick?: (session: Session) => void; /** * Callback when a CLAUDE.md file should be edited */ onEditClaudeFile?: (file: ClaudeMdFile) => void; /** * Optional className for styling */ className?: string; } const ITEMS_PER_PAGE = 5; /** * SessionList component - Displays paginated sessions for a specific project * * @example * setSelectedProject(null)} * onSessionClick={(session) => console.log('Selected session:', session)} * /> */ export const SessionList: React.FC = ({ sessions, projectPath, onBack, onSessionClick, onEditClaudeFile, className, }) => { const [currentPage, setCurrentPage] = useState(1); // Calculate pagination const totalPages = Math.ceil(sessions.length / ITEMS_PER_PAGE); const startIndex = (currentPage - 1) * ITEMS_PER_PAGE; const endIndex = startIndex + ITEMS_PER_PAGE; const currentSessions = sessions.slice(startIndex, endIndex); // Reset to page 1 if sessions change React.useEffect(() => { setCurrentPage(1); }, [sessions.length]); return (

{projectPath}

{sessions.length} session{sessions.length !== 1 ? 's' : ''}

{/* CLAUDE.md Memories Dropdown */} {onEditClaudeFile && ( )}
{currentSessions.map((session, index) => ( { // Emit a special event for Claude Code session navigation const event = new CustomEvent('claude-session-selected', { detail: { session, projectPath } }); window.dispatchEvent(event); onSessionClick?.(session); }} >

{session.id}

{/* First message preview */} {session.first_message && (
First message:

{truncateText(getFirstLine(session.first_message), 100)}

)} {/* Metadata */}
{/* Message timestamp if available, otherwise file creation time */}
{session.message_timestamp ? formatISOTimestamp(session.message_timestamp) : formatUnixTimestamp(session.created_at) }
{session.todo_data && (
Has todo
)}
))}
); };