diff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsx index 04d86f81eeb..3a30fbb2c7e 100644 --- a/apps/web/src/components/DiffPanel.tsx +++ b/apps/web/src/components/DiffPanel.tsx @@ -11,6 +11,8 @@ import { CheckIcon, ChevronDownIcon, ChevronRightIcon, + ChevronsDownUpIcon, + ChevronsUpDownIcon, Columns2Icon, PilcrowIcon, Rows3Icon, @@ -32,6 +34,7 @@ import { resolveDiffThemeName, resolveFileDiffPath, } from "../lib/diffRendering"; +import { areAllDiffFilesCollapsed, toggleAllDiffFiles } from "../lib/diffCollapse"; import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries"; import { useProject, useThread } from "../state/entities"; import { resolveThreadRouteRef } from "../threadRoutes"; @@ -39,6 +42,7 @@ import { useClientSettings } from "../hooks/useSettings"; import { formatShortTimestamp } from "../timestampFormat"; import { DiffPanelLoadingState, DiffPanelShell, type DiffPanelMode } from "./DiffPanelShell"; import { AnnotatableCodeView, type AnnotatableCodeViewHandle } from "./diffs/AnnotatableCodeView"; +import { Button } from "./ui/button"; import { ToggleGroup, Toggle } from "./ui/toggle-group"; import { Switch } from "./ui/switch"; import { @@ -446,6 +450,8 @@ export default function DiffPanel({ }), [collapsedDiffFileKeys, renderableFiles], ); + const diffFileKeys = useMemo(() => codeViewFiles.map((file) => file.fileKey), [codeViewFiles]); + const allDiffFilesCollapsed = areAllDiffFilesCollapsed(diffFileKeys, collapsedDiffFileKeys); useEffect(() => { if (!selectedFilePath) return; @@ -496,6 +502,18 @@ export default function DiffPanel({ [collapseScopeKey], ); + const toggleDiffFileCollapse = useCallback(() => { + setCollapsedDiffFiles((current) => { + const currentKeys = + current.scopeKey === collapseScopeKey ? current.fileKeys : EMPTY_COLLAPSED_DIFF_FILE_KEYS; + + return { + scopeKey: collapseScopeKey, + fileKeys: toggleAllDiffFiles(diffFileKeys, currentKeys), + }; + }); + }, [collapseScopeKey, diffFileKeys]); + const selectTurn = (turnId: TurnId) => { if (!routeThreadRef) return; useDiffPanelStore.getState().selectTurn(routeThreadRef, turnId); @@ -695,6 +713,30 @@ export default function DiffPanel({ )}