import { useCallback, useState } from 'react'; import { useGitPanelController } from '../hooks/useGitPanelController'; import { useRevertLocalCommit } from '../hooks/useRevertLocalCommit'; import type { ConfirmationRequest, GitPanelProps, GitPanelView } from '../types/types'; import { getChangedFileCount } from '../utils/gitPanelUtils'; import ChangesView from '../view/changes/ChangesView'; import HistoryView from '../view/history/HistoryView'; import BranchesView from '../view/branches/BranchesView'; import GitPanelHeader from '../view/GitPanelHeader'; import GitRepositoryErrorState from '../view/GitRepositoryErrorState'; import GitViewTabs from '../view/GitViewTabs'; import ConfirmActionModal from '../view/modals/ConfirmActionModal'; export default function GitPanel({ selectedProject, isMobile = false, onFileOpen }: GitPanelProps) { const [activeView, setActiveView] = useState('changes'); const [wrapText, setWrapText] = useState(true); const [hasExpandedFiles, setHasExpandedFiles] = useState(false); const [confirmAction, setConfirmAction] = useState(null); const { gitStatus, gitDiff, isLoading, currentBranch, branches, localBranches, remoteBranches, recentCommits, commitDiffs, remoteStatus, isCreatingBranch, isFetching, isPulling, isPushing, isPublishing, isCreatingInitialCommit, operationError, clearOperationError, refreshAll, switchBranch, createBranch, deleteBranch, handleFetch, handlePull, handlePush, handlePublish, discardChanges, deleteUntrackedFile, fetchCommitDiff, generateCommitMessage, commitChanges, createInitialCommit, openFile, } = useGitPanelController({ selectedProject, activeView, onFileOpen, }); const { isRevertingLocalCommit, revertLatestLocalCommit } = useRevertLocalCommit({ // `projectId` (DB primary key) is forwarded to the revert API which uses it // as the `project` body param. projectId: selectedProject?.projectId ?? null, onSuccess: refreshAll, }); const executeConfirmedAction = useCallback(async () => { if (!confirmAction) return; const actionToExecute = confirmAction; setConfirmAction(null); try { await actionToExecute.onConfirm(); } catch (error) { console.error('Error executing confirmation action:', error); } }, [confirmAction]); const changeCount = getChangedFileCount(gitStatus); if (!selectedProject) { return (

Select a project to view source control

); } return (
{gitStatus?.error ? ( ) : ( <> {activeView === 'changes' && ( )} {activeView === 'history' && ( )} {activeView === 'branches' && ( )} )} setConfirmAction(null)} onConfirm={() => { void executeConfirmedAction(); }} />
); }