-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathcommandPaletteStore.ts
More file actions
40 lines (37 loc) · 1.11 KB
/
commandPaletteStore.ts
File metadata and controls
40 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { create } from "zustand";
interface CommandPaletteOpenIntent {
kind: "add-project";
requestId: number;
}
interface CommandPaletteStore {
open: boolean;
openIntent: CommandPaletteOpenIntent | null;
checkpointRewindRequestId: number;
setOpen: (open: boolean) => void;
toggleOpen: () => void;
openAddProject: () => void;
openCheckpointRewind: () => void;
clearOpenIntent: () => void;
}
export const useCommandPaletteStore = create<CommandPaletteStore>((set) => ({
open: false,
openIntent: null,
checkpointRewindRequestId: 0,
setOpen: (open) => set({ open, ...(open ? {} : { openIntent: null }) }),
toggleOpen: () =>
set((state) => ({ open: !state.open, ...(state.open ? { openIntent: null } : {}) })),
openAddProject: () =>
set((state) => ({
open: true,
openIntent: {
kind: "add-project",
requestId: (state.openIntent?.requestId ?? 0) + 1,
},
})),
openCheckpointRewind: () =>
set((state) => ({
open: false,
checkpointRewindRequestId: state.checkpointRewindRequestId + 1,
})),
clearOpenIntent: () => set({ openIntent: null }),
}));