Files
openchamber/packages/ui/src/stores/usePendingOpenCodeRestartStore.ts
T
Cursor AgentandSerhii Dziupin 57819dd164 Accumulate OpenCode settings restarts behind Apply & Restart
Defer OpenCode reloads after settings mutations, track pending changes,
and expose a top-right Apply & Restart OpenCode action with a counter so
sessions stay available until the user explicitly applies.

Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>
2026-08-03 06:56:38 +00:00

67 lines
1.5 KiB
TypeScript

import { create } from 'zustand';
export type PendingOpenCodeRestartScope =
| 'agents'
| 'providers'
| 'commands'
| 'mcp'
| 'plugins'
| 'skills'
| 'behavior'
| 'cli'
| 'all';
export type PendingOpenCodeRestartChange = {
id: string;
scope: PendingOpenCodeRestartScope;
label?: string;
recordedAt: number;
};
type PendingOpenCodeRestartState = {
changes: PendingOpenCodeRestartChange[];
isApplying: boolean;
recordChange: (input: {
scope: PendingOpenCodeRestartScope;
id?: string;
label?: string;
}) => void;
setApplying: (isApplying: boolean) => void;
clear: () => void;
};
let changeSeq = 0;
const nextChangeId = (scope: PendingOpenCodeRestartScope, id?: string): string => {
changeSeq += 1;
return id?.trim() ? `${scope}:${id.trim()}:${changeSeq}` : `${scope}:${changeSeq}`;
};
export const usePendingOpenCodeRestartStore = create<PendingOpenCodeRestartState>((set) => ({
changes: [],
isApplying: false,
recordChange: ({ scope, id, label }) => {
const entry: PendingOpenCodeRestartChange = {
id: nextChangeId(scope, id),
scope,
label,
recordedAt: Date.now(),
};
set((state) => ({
changes: [...state.changes, entry],
}));
},
setApplying: (isApplying) => {
set({ isApplying });
},
clear: () => {
set({ changes: [], isApplying: false });
},
}));
export const selectPendingOpenCodeRestartCount = (state: PendingOpenCodeRestartState): number =>
state.changes.length;