Files
paseo/packages/app/src/git/working-diff-comparison/index.ts
T
Mohamed Boudra c63e1204b0 Review all branch changes by default without automatic scope switching (#7576)
* feat(git): default review to all branch changes

Keep the selected comparison stable while agents edit and commit so reviewing the complete result does not require switching scopes or interrupt unfinished comments.

* test(git): release Windows checkout handles during cleanup

Allow transient filesystem handles from subscription teardown to close before removing the test repository.
2026-10-21 18:28:23 +07:00

57 lines
1.8 KiB
TypeScript

import { useCallback } from "react";
import { create } from "zustand";
import {
resolveWorkingDiffComparisonFromState,
selectWorkingDiffComparisonInState,
type WorkingDiffCheckoutIdentity,
type WorkingDiffComparison,
type WorkingDiffComparisonState,
} from "./state";
interface WorkingDiffComparisonStore extends WorkingDiffComparisonState {
select: (
input: WorkingDiffCheckoutIdentity & {
comparison: WorkingDiffComparison;
},
) => void;
}
const useWorkingDiffComparisonStore = create<WorkingDiffComparisonStore>((set) => ({
overrides: {},
select: (input) => set((state) => selectWorkingDiffComparisonInState(state, input)),
}));
export function useWorkingDiffComparison(input: WorkingDiffCheckoutIdentity): {
comparison: WorkingDiffComparison;
selectComparison: (comparison: WorkingDiffComparison) => void;
} {
const { serverId, workspaceId, cwd } = input;
const comparison = useWorkingDiffComparisonStore((state) =>
resolveWorkingDiffComparisonFromState(state, { serverId, workspaceId, cwd }),
);
const select = useWorkingDiffComparisonStore((state) => state.select);
const selectComparison = useCallback(
(next: WorkingDiffComparison) => select({ serverId, workspaceId, cwd, comparison: next }),
[cwd, select, serverId, workspaceId],
);
return { comparison, selectComparison };
}
export function selectWorkingDiffComparison(
input: WorkingDiffCheckoutIdentity & {
comparison: WorkingDiffComparison;
},
): void {
useWorkingDiffComparisonStore.getState().select(input);
}
export function resolveWorkingDiffComparison(
input: WorkingDiffCheckoutIdentity,
): WorkingDiffComparison {
return resolveWorkingDiffComparisonFromState(useWorkingDiffComparisonStore.getState(), input);
}
export function resetWorkingDiffComparisons(): void {
useWorkingDiffComparisonStore.setState({ overrides: {} });
}