import { useState } from 'react' import { useGitStatus } from '@/api/git' import { useGit } from '@/hooks/useGit' import { GitFlatFileList } from './GitFlatFileList' import { Button } from '@/components/ui/button' import { Textarea } from '@/components/ui/textarea' import { FileDiffView } from '@/components/file-browser/FileDiffView' import { DiscardDialog } from '@/components/ui/discard-dialog' import { Loader2, GitCommit, FileText, AlertCircle } from 'lucide-react' interface ChangesTabProps { repoId: number onFileSelect: (path: string, staged: boolean) => void onClearFileSelection?: () => void selectedFile?: {path: string, staged: boolean} isMobile: boolean onError?: (error: unknown) => void } export function ChangesTab({ repoId, onFileSelect, onClearFileSelection, selectedFile, isMobile, onError }: ChangesTabProps) { const { data: status, isLoading, error } = useGitStatus(repoId) const git = useGit(repoId, onError) const [commitMessage, setCommitMessage] = useState('') const [discardDialogOpen, setDiscardDialogOpen] = useState(false) const [discardPaths, setDiscardPaths] = useState([]) const [discardStaged, setDiscardStaged] = useState(false) const stagedFiles = status?.files.filter(f => f.staged) || [] const unstagedFiles = status?.files.filter(f => !f.staged) || [] const canCommit = commitMessage.trim() && stagedFiles.length > 0 && !git.commit.isPending const handleStage = (paths: string[]) => { git.stageFiles.mutate(paths) } const handleUnstage = (paths: string[]) => { git.unstageFiles.mutate(paths) } const handleDiscard = (paths: string[], staged: boolean) => { setDiscardPaths(paths) setDiscardStaged(staged) setDiscardDialogOpen(true) } const confirmDiscard = () => { git.discardFiles.mutate({ paths: discardPaths, staged: discardStaged }) setDiscardDialogOpen(false) setDiscardPaths([]) } const cancelDiscard = () => { setDiscardDialogOpen(false) setDiscardPaths([]) } const handleCommit = () => { git.commit.mutate({ message: commitMessage.trim() }) setCommitMessage('') } if (isLoading) { return (
) } if (error) { return (

Failed to load git status

{error.message}

) } if (!status) return null if (isMobile && selectedFile) { return (
) } else { return (
{status.hasChanges ? ( <> {stagedFiles.length > 0 && ( )} {unstagedFiles.length > 0 && ( )} ) : (

No uncommitted changes

)}
{status.hasChanges && (