mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-03-11 17:07:40 +00:00
Refactor Settings, FileTree, GitPanel, Shell, and CodeEditor components (#402)
This commit is contained in:
71
src/components/git-panel/view/history/CommitHistoryItem.tsx
Normal file
71
src/components/git-panel/view/history/CommitHistoryItem.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
import { ChevronDown, ChevronRight } from 'lucide-react';
|
||||
import DiffViewer from '../../../DiffViewer.jsx';
|
||||
import type { GitCommitSummary } from '../../types/types';
|
||||
|
||||
type DiffViewerProps = {
|
||||
diff: string;
|
||||
fileName: string;
|
||||
isMobile: boolean;
|
||||
wrapText: boolean;
|
||||
};
|
||||
|
||||
const DiffViewerComponent = DiffViewer as unknown as (props: DiffViewerProps) => JSX.Element;
|
||||
|
||||
type CommitHistoryItemProps = {
|
||||
commit: GitCommitSummary;
|
||||
isExpanded: boolean;
|
||||
diff?: string;
|
||||
isMobile: boolean;
|
||||
wrapText: boolean;
|
||||
onToggle: () => void;
|
||||
};
|
||||
|
||||
export default function CommitHistoryItem({
|
||||
commit,
|
||||
isExpanded,
|
||||
diff,
|
||||
isMobile,
|
||||
wrapText,
|
||||
onToggle,
|
||||
}: CommitHistoryItemProps) {
|
||||
return (
|
||||
<div className="border-b border-border last:border-0">
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={isExpanded}
|
||||
className="w-full flex items-start p-3 hover:bg-accent/50 cursor-pointer transition-colors text-left bg-transparent border-0"
|
||||
onClick={onToggle}
|
||||
>
|
||||
<span className="mr-2 mt-1 p-0.5 hover:bg-accent rounded">
|
||||
{isExpanded ? <ChevronDown className="w-3 h-3" /> : <ChevronRight className="w-3 h-3" />}
|
||||
</span>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium text-foreground truncate">{commit.message}</p>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
{commit.author}
|
||||
{' \u2022 '}
|
||||
{commit.date}
|
||||
</p>
|
||||
</div>
|
||||
<span className="text-sm font-mono text-muted-foreground/60 flex-shrink-0">
|
||||
{commit.hash.substring(0, 7)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
{isExpanded && diff && (
|
||||
<div className="bg-muted/50">
|
||||
<div className="max-h-96 overflow-y-auto p-2">
|
||||
<div className="text-sm font-mono text-muted-foreground mb-2">
|
||||
{commit.stats}
|
||||
</div>
|
||||
<DiffViewerComponent diff={diff} fileName="commit" isMobile={isMobile} wrapText={wrapText} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
77
src/components/git-panel/view/history/HistoryView.tsx
Normal file
77
src/components/git-panel/view/history/HistoryView.tsx
Normal file
@@ -0,0 +1,77 @@
|
||||
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<void>;
|
||||
};
|
||||
|
||||
export default function HistoryView({
|
||||
isMobile,
|
||||
isLoading,
|
||||
recentCommits,
|
||||
commitDiffs,
|
||||
wrapText,
|
||||
onFetchCommitDiff,
|
||||
}: HistoryViewProps) {
|
||||
const [expandedCommits, setExpandedCommits] = useState<Set<string>>(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 (
|
||||
<div className={`flex-1 overflow-y-auto ${isMobile ? 'pb-mobile-nav' : ''}`}>
|
||||
{isLoading ? (
|
||||
<div className="flex items-center justify-center h-32">
|
||||
<RefreshCw className="w-5 h-5 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
) : recentCommits.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center h-32 text-muted-foreground">
|
||||
<History className="w-10 h-10 mb-2 opacity-40" />
|
||||
<p className="text-sm">No commits found</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className={isMobile ? 'pb-4' : ''}>
|
||||
{recentCommits.map((commit) => (
|
||||
<CommitHistoryItem
|
||||
key={commit.hash}
|
||||
commit={commit}
|
||||
isExpanded={expandedCommits.has(commit.hash)}
|
||||
diff={commitDiffs[commit.hash]}
|
||||
isMobile={isMobile}
|
||||
wrapText={wrapText}
|
||||
onToggle={() => toggleCommitExpanded(commit.hash)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user