Files
t3code/apps/web/src/commandPaletteStore.ts
2026-04-14 23:26:05 -07:00

33 lines
886 B
TypeScript

import { create } from "zustand";
interface CommandPaletteOpenIntent {
kind: "add-project";
requestId: number;
}
interface CommandPaletteStore {
open: boolean;
openIntent: CommandPaletteOpenIntent | null;
setOpen: (open: boolean) => void;
toggleOpen: () => void;
openAddProject: () => void;
clearOpenIntent: () => void;
}
export const useCommandPaletteStore = create<CommandPaletteStore>((set) => ({
open: false,
openIntent: null,
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,
},
})),
clearOpenIntent: () => set({ openIntent: null }),
}));