"use client"; import { IconArrowBackUp, IconExternalLink, IconPlus, IconMinus, IconCheck, IconChevronRight, IconGitCommit, IconLoader2, IconColumns, } from "@tabler/icons-react"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@kandev/ui/alert-dialog"; import { LineStat } from "@/components/diff-stat"; import { cn } from "@/lib/utils"; import type { FileInfo } from "@/lib/state/store"; import { FileStatusIcon } from "./file-status-icon"; export type ChangedFileItem = { path: string; status: FileInfo["status"]; staged: boolean; plus: number | undefined; minus: number | undefined; oldPath: string | undefined; }; export const splitPath = (path: string) => { const lastSlash = path.lastIndexOf("/"); if (lastSlash === -1) return { folder: "", file: path }; return { folder: path.slice(0, lastSlash), file: path.slice(lastSlash + 1), }; }; export function DiscardDialog({ open, onOpenChange, fileToDiscard, onConfirm, }: { open: boolean; onOpenChange: (open: boolean) => void; fileToDiscard: string | null; onConfirm: () => void; }) { return ( Discard changes? This will permanently discard all changes to{" "} {fileToDiscard}. This action cannot be undone. Cancel Discard ); } export function DiffTabContent({ changedFiles, pendingStageFiles, commits, expandedCommit, commitDiffs, loadingCommitSha, reviewedCount, totalFileCount, reviewProgressPercent, onSelectDiff, onStage, onUnstage, onDiscard, onOpenInPanel, onOpenInEditor, onToggleCommit, }: { changedFiles: ChangedFileItem[]; pendingStageFiles: Set; commits: Array<{ commit_sha: string; commit_message: string; insertions: number; deletions: number; }>; expandedCommit: string | null; commitDiffs: Record>; loadingCommitSha: string | null; reviewedCount: number; totalFileCount: number; reviewProgressPercent: number; onSelectDiff: (path: string, content?: string) => void; onStage: (path: string) => void; onUnstage: (path: string) => void; onDiscard: (path: string) => void; onOpenInPanel: (path: string) => void; onOpenInEditor: (path: string) => void; onToggleCommit: (sha: string) => void; }) { return ( <> {changedFiles.length > 0 && ( )} {commits.length > 0 && ( )} {changedFiles.length === 0 && commits.length === 0 && ( Your changed files will appear here )} > ); } function UncommittedFilesSection({ changedFiles, pendingStageFiles, onSelectDiff, onStage, onUnstage, onDiscard, onOpenInPanel, onOpenInEditor, }: { changedFiles: ChangedFileItem[]; pendingStageFiles: Set; onSelectDiff: (path: string) => void; onStage: (path: string) => void; onUnstage: (path: string) => void; onDiscard: (path: string) => void; onOpenInPanel: (path: string) => void; onOpenInEditor: (path: string) => void; }) { return ( Uncommitted ({changedFiles.length}) {changedFiles.map((file) => ( ))} ); } function UncommittedFileRow({ file, isPending, onSelectDiff, onStage, onUnstage, onDiscard, onOpenInPanel, onOpenInEditor, }: { file: ChangedFileItem; isPending: boolean; onSelectDiff: (path: string) => void; onStage: (path: string) => void; onUnstage: (path: string) => void; onDiscard: (path: string) => void; onOpenInPanel: (path: string) => void; onOpenInEditor: (path: string) => void; }) { const { folder, file: name } = splitPath(file.path); return ( onSelectDiff(file.path)} > {folder && {folder}/} {name} ); } function FileStageIcon({ isPending, staged, path, onStage, onUnstage, }: { isPending: boolean; staged: boolean; path: string; onStage: (path: string) => void; onUnstage: (path: string) => void; }) { if (isPending) { return ( ); } if (staged) { return ( { e.stopPropagation(); void onUnstage(path); }} > ); } return ( { e.stopPropagation(); void onStage(path); }} > ); } function FileRowActionButtons({ path, onDiscard, onOpenInPanel, onOpenInEditor, }: { path: string; onDiscard: (p: string) => void; onOpenInPanel: (p: string) => void; onOpenInEditor: (p: string) => void; }) { return ( { e.stopPropagation(); onDiscard(path); }} > Discard changes { e.stopPropagation(); onOpenInPanel(path); }} > Open side-by-side { e.stopPropagation(); onOpenInEditor(path); }} > Open in external editor ); } export function CommitsExpandableSection({ commits, expandedCommit, commitDiffs, loadingCommitSha, onToggleCommit, onSelectDiff, }: { commits: Array<{ commit_sha: string; commit_message: string; insertions: number; deletions: number; }>; expandedCommit: string | null; commitDiffs: Record>; loadingCommitSha: string | null; onToggleCommit: (sha: string) => void; onSelectDiff: (path: string, content?: string) => void; }) { return ( Commits ({commits.length}) {commits.map((commit) => ( ))} ); } function CommitRow({ commit, isExpanded, files, isLoading, onToggle, onSelectDiff, }: { commit: { commit_sha: string; commit_message: string; insertions: number; deletions: number }; isExpanded: boolean; files?: Record; isLoading: boolean; onToggle: (sha: string) => void; onSelectDiff: (path: string, content?: string) => void; }) { return ( onToggle(commit.commit_sha)} > {commit.commit_sha.slice(0, 7)}{" "} {commit.commit_message} +{commit.insertions} {"/"} -{commit.deletions} {isLoading && } {isExpanded && files && ( {Object.entries(files).map(([path, file]) => { const { folder, file: fileName } = splitPath(path); return ( onSelectDiff(path, file.diff)} > {folder && {folder}/} {fileName} +{file.additions ?? 0} {"/"} -{file.deletions ?? 0} ); })} )} ); } export function FilesPanelReviewProgress({ reviewedCount, totalFileCount, reviewProgressPercent, }: { reviewedCount: number; totalFileCount: number; reviewProgressPercent: number; }) { if (totalFileCount <= 0) return null; return ( window.dispatchEvent(new CustomEvent("switch-to-changes-tab"))} > {reviewedCount}/{totalFileCount} reviewed {reviewedCount} of {totalFileCount} files reviewed ); }
{folder && {folder}/} {name}
{commit.commit_sha.slice(0, 7)}{" "} {commit.commit_message}
{commit.commit_sha.slice(0, 7)}