/** * VersionBrowser — Version list for plan diff * * Shows all versions of the current plan and allows selecting * which version to diff against. */ import React, { useEffect } from "react"; import type { VersionInfo, VersionEntry } from "../../hooks/usePlanDiff"; interface VersionBrowserProps { versionInfo: VersionInfo | null; versions: VersionEntry[]; selectedBaseVersion: number | null; onSelectBaseVersion: (version: number) => void; isPlanDiffActive: boolean; hasPreviousVersion: boolean; onActivatePlanDiff: () => void; isLoading: boolean; isSelectingVersion: boolean; fetchingVersion: number | null; onFetchVersions: () => void; } function relativeTime(timestamp: string): string { if (!timestamp) return ""; const now = Date.now(); const then = new Date(timestamp).getTime(); const diff = now - then; if (diff < 60_000) return "just now"; if (diff < 3_600_000) return `${Math.floor(diff / 60_000)}m ago`; if (diff < 86_400_000) return `${Math.floor(diff / 3_600_000)}h ago`; if (diff < 604_800_000) return `${Math.floor(diff / 86_400_000)}d ago`; return new Date(timestamp).toLocaleDateString(); } export const VersionBrowser: React.FC = ({ versionInfo, versions, selectedBaseVersion, onSelectBaseVersion, isPlanDiffActive, hasPreviousVersion, onActivatePlanDiff, isLoading, isSelectingVersion, fetchingVersion, onFetchVersions, }) => { // Fetch version list once versionInfo is available useEffect(() => { if (versionInfo && versions.length === 0) { onFetchVersions(); } }, [versionInfo, versions.length, onFetchVersions]); if (!versionInfo) { return (
No version history available.
); } const currentVersion = versionInfo.version; const totalVersions = versionInfo.totalVersions; return (
{/* Current version info */}
Current Plan
Version {currentVersion} of {totalVersions}
{/* Show Diff button if not active */} {hasPreviousVersion && !isPlanDiffActive && ( )} {/* Version list */} {totalVersions > 1 && (
Compare Against
{isLoading ? (
Loading...
) : (
{versions .filter((v) => v.version !== currentVersion) .reverse() .map((v) => { const isSelected = selectedBaseVersion === v.version; return ( ); })}
)}
)}
); };