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>
This commit is contained in:
co-authored by
Serhii Dziupin
parent
775da6e9f4
commit
57819dd164
@@ -0,0 +1,66 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user