Files
ProjectE/apps/web/src/lib/stores/use-keyboard-shortcuts-store.ts
T
Hermes e86a7c0672 T5/Phase 3: SPA shell + navigation
- TanStack Router with type-safe file-based routes
- Sidebar: collapsible, workspace switcher, 12 nav links, user menu
- Topbar: search, quick-add, notifications, user avatar
- cmdk command palette: nav + create + search + @mentions
- Keyboard shortcuts: Cmd+K palette, g+t/h/p/n/c/g/s navigation, ? help
- Theme: dark default, accent picker (slate/blue/green/purple/orange), persisted to localStorage
- Auth: login -> /, logout -> /login, 401 redirect
- Placeholder pages for all 13 nav routes (real in T6/T7)
- Typed API client with useApiQuery/useApiMutation hooks
2026-08-01 02:00:24 +00:00

53 lines
1.8 KiB
TypeScript

import { create } from "zustand";
import { persist } from "zustand/middleware";
interface Shortcut {
key: string;
description: string;
action: string;
enabled: boolean;
}
interface KeyboardShortcutsState {
enabled: boolean;
shortcuts: Shortcut[];
setEnabled: (enabled: boolean) => void;
updateShortcut: (key: string, updates: Partial<Shortcut>) => void;
resetShortcuts: () => void;
}
const defaultShortcuts: Shortcut[] = [
{ key: "g+d", description: "Go to Dashboard", action: "navigate_dashboard", enabled: true },
{ key: "g+t", description: "Go to Tasks", action: "navigate_tasks", enabled: true },
{ key: "g+h", description: "Go to Habits", action: "navigate_habits", enabled: true },
{ key: "g+p", description: "Go to Projects", action: "navigate_projects", enabled: true },
{ key: "g+n", description: "Go to Notes", action: "navigate_notes", enabled: true },
{ key: "g+c", description: "Go to Calendar", action: "navigate_calendar", enabled: true },
{ key: "g+g", description: "Go to Graph", action: "navigate_graph", enabled: true },
{ key: "g+s", description: "Go to Settings", action: "navigate_settings", enabled: true },
{ key: "/", description: "Focus search", action: "focus_search", enabled: true },
{ key: "?", description: "Show shortcuts help", action: "show_help", enabled: true },
];
export const useKeyboardShortcutsStore = create<KeyboardShortcutsState>()(
persist(
(set) => ({
enabled: true,
shortcuts: defaultShortcuts,
setEnabled: (enabled) => set({ enabled }),
updateShortcut: (key, updates) =>
set((state) => ({
shortcuts: state.shortcuts.map((s) =>
s.key === key ? { ...s, ...updates } : s
),
})),
resetShortcuts: () => set({ shortcuts: defaultShortcuts }),
}),
{
name: "project-e-keyboard-shortcuts",
}
)
);