import { History, RefreshCw } from 'lucide-react'; import { useCallback, useState } from 'react'; import type { GitDiffMap, GitCommitSummary } from '../../types/types'; import CommitHistoryItem from './CommitHistoryItem'; type HistoryViewProps = { isMobile: boolean; isLoading: boolean; recentCommits: GitCommitSummary[]; commitDiffs: GitDiffMap; wrapText: boolean; onFetchCommitDiff: (commitHash: string) => Promise; }; export default function HistoryView({ isMobile, isLoading, recentCommits, commitDiffs, wrapText, onFetchCommitDiff, }: HistoryViewProps) { const [expandedCommits, setExpandedCommits] = useState>(new Set()); const toggleCommitExpanded = useCallback( (commitHash: string) => { const isExpanding = !expandedCommits.has(commitHash); setExpandedCommits((previous) => { const next = new Set(previous); if (next.has(commitHash)) { next.delete(commitHash); } else { next.add(commitHash); } return next; }); // Load commit diff lazily only the first time a commit is expanded. if (isExpanding && !commitDiffs[commitHash]) { onFetchCommitDiff(commitHash).catch((err) => { console.error('Failed to fetch commit diff:', err); }); } }, [commitDiffs, expandedCommits, onFetchCommitDiff, setExpandedCommits], ); return (
{isLoading ? (
) : recentCommits.length === 0 ? (

No commits found

) : (
{recentCommits.map((commit) => ( toggleCommitExpanded(commit.hash)} /> ))}
)}
); }