import { useState } from 'react' import { useGitStatus, getApiErrorMessage } from '@/api/git' import { useGit } from '@/hooks/useGit' import { ChangesTab } from './ChangesTab' import { CommitsTab } from './CommitsTab' import { BranchesTab } from './BranchesTab' import { FileDiffView } from '@/components/file-browser/FileDiffView' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { GIT_UI_COLORS } from '@/lib/git-status-styles' import { Loader2, GitBranch, FileCode, History, Upload, ArrowUp, ArrowDown, RefreshCw, ArrowDownFromLine, X, } from 'lucide-react' import { cn } from '@/lib/utils' import { useMobile } from '@/hooks/useMobile' import { showToast } from '@/lib/toast' interface SourceControlPanelProps { repoId: number isOpen: boolean onClose: () => void currentBranch: string repoUrl?: string | null isRepoWorktree?: boolean repoName?: string } type Tab = 'changes' | 'commits' | 'branches' export function SourceControlPanel({ repoId, isOpen, onClose, currentBranch, repoUrl, isRepoWorktree, repoName, }: SourceControlPanelProps) { const [activeTab, setActiveTab] = useState('changes') const [selectedFile, setSelectedFile] = useState<{path: string, staged: boolean} | undefined>() const { data: status } = useGitStatus(repoId) const git = useGit(repoId) const isMobile = useMobile() const handleGitAction = async (action: () => Promise) => { try { await action() } catch (error: unknown) { const message = getApiErrorMessage(error) showToast.error(message) } } const tabs: { id: Tab; label: string; icon: React.ElementType }[] = [ { id: 'changes', label: 'Changes', icon: FileCode }, { id: 'commits', label: 'Commits', icon: History }, { id: 'branches', label: 'Branches', icon: GitBranch }, ] const changesCount = status?.files.length || 0 const stagedCount = status?.files.filter(f => f.staged).length || 0 const content = (
{currentBranch}
{status && (status.ahead > 0 || status.behind > 0) && (
{status.ahead > 0 && ( {status.ahead} )} {status.behind > 0 && ( {status.behind} )}
)}
{tabs.map((tab) => { const Icon = tab.icon return ( ) })}
{activeTab === 'changes' && ( setSelectedFile({ path, staged })} selectedFile={selectedFile} isMobile={isMobile} /> )} {activeTab === 'commits' && ( )} {activeTab === 'branches' && ( )}
{selectedFile && !isMobile && (
{selectedFile.path}
)}
) return ( !open && onClose()}> {isMobile && repoName ? repoName : 'Source Control'} {isMobile && ( )}
{content}
) }