import React from 'react' import { useNavigate } from '@tanstack/react-router' import { EmptyState, ToolDot, Spark } from '../../primitives' import type { Project } from '../../api/adapters' interface ProjectsTableProps { projects: Project[] cursor: number onCursor: (i: number) => void onOpen: (p: Project) => void } const COLS = '1fr 90px 90px 110px 110px 90px' // Format TOK: 12400 → "12.4k"; small numbers unchanged function formatTok(n: number): string { if (n >= 1000) { return (n / 1000).toFixed(1) + 'k' } return String(n) } // Format lastActive ISO string: recent = "Apr 25 11:08"; empty = "—" function formatLastActive(iso: string): string { if (!iso) return '—' const d = new Date(iso) const now = new Date() const diffMs = now.getTime() - d.getTime() const h24 = 24 * 60 * 60 * 1000 if (diffMs <= h24) { return d.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false }) } return ( d.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }) + ' ' + d.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false }) ) } export function ProjectsTable({ projects, cursor, onCursor, onOpen }: ProjectsTableProps): React.JSX.Element { const navigate = useNavigate() if (projects.length === 0) { return (
) } function handleOpen(p: Project) { onOpen(p) // Route /project/$ is added in Phase 4; cast needed until routeTree is regenerated. // eslint-disable-next-line @typescript-eslint/no-explicit-any void (navigate as any)({ to: '/project/$', params: { _splat: encodeURIComponent(p.cwd) } }) } const maxSessions = Math.max(...projects.map(p => p.sessions), 1) return (
cwd sessions tok last top tool activity
{projects.map((p, i) => { const isCursor = i === cursor // Build a minimal sparkline: normalise sessions relative to max, scaled to 0–12px height const sparkPoints = [0, (p.sessions / maxSessions) * 12] return (
{ onCursor(i); handleOpen(p) }} onMouseEnter={() => onCursor(i)} > {p.cwd} {p.sessions} {formatTok(p.tokensIn + p.tokensOut)} {formatLastActive(p.lastActive)} {p.topTool ? ( <> {' '}{p.topTool} ) : ( )}
) })}
) }