mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-10 10:25:03 +00:00
* 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.
57 lines
1.8 KiB
TypeScript
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: {} });
|
|
}
|