import { useEffect } from "react"; import type { ListSnapshotsResponse } from "~/client/api-client"; import { ByteSize } from "~/client/components/bytes-size"; import { Card, CardContent } from "~/client/components/ui/card"; import { formatDateWithMonth, formatShortDate, formatTime } from "~/client/lib/datetime"; import { cn } from "~/client/lib/utils"; interface Props { snapshots: ListSnapshotsResponse; snapshotId?: string; loading?: boolean; error?: string; onSnapshotSelect: (snapshotId: string) => void; } export const SnapshotTimeline = (props: Props) => { const { snapshots, snapshotId, loading, onSnapshotSelect, error } = props; useEffect(() => { if (!snapshotId && snapshots.length > 0) { onSnapshotSelect(snapshots[snapshots.length - 1].short_id); } }, [snapshotId, snapshots, onSnapshotSelect]); if (error) { return (

{error}

); } if (loading) { return (

Loading snapshots...

); } if (snapshots.length === 0) { return (

No snapshots available

); } return (
{snapshots.map((snapshot, index) => { const date = new Date(snapshot.time); const isSelected = snapshotId === snapshot.short_id; const isLatest = index === snapshots.length - 1; return ( ); })}
{snapshots.length} snapshots {formatDateWithMonth(snapshots[0].time)} - {formatDateWithMonth(snapshots.at(-1)?.time)}
); };