learning_ai_notes/web/src/components/KeyboardShortcuts.tsx
saravanakumardb1 12d90098eb feat(web): saved views CRUD, keyboard shortcuts, debounced search
- saved-views-client.ts: full CRUD client for backend saved-views module
- use-keyboard-shortcuts.ts: reusable hook for global keyboard shortcuts
- KeyboardShortcuts.tsx: wired into (app) layout — Cmd+K search, Cmd+N workspaces, Cmd+Shift+D dashboard, Cmd+Shift+R reviews, Esc blur
- use-debounce.ts: shared debounce hook (replaces inline setTimeout in search)
- Search page: saved views loaded from backend with save/delete UI
- Search page: search debounced at 250ms via useDebounce hook
- Updated search page test to mock saved-views-client and useDebounce

Verification: web typecheck + 6/6 tests pass.
2026-03-10 19:39:28 -07:00

54 lines
1.2 KiB
TypeScript

"use client";
import { useRouter } from "next/navigation";
import { useMemo } from "react";
import { useKeyboardShortcuts, type KeyboardShortcut } from "@/lib/use-keyboard-shortcuts";
export function KeyboardShortcuts() {
const router = useRouter();
const shortcuts = useMemo<KeyboardShortcut[]>(
() => [
{
key: "k",
meta: true,
handler: () => router.push("/search"),
description: "Open search",
},
{
key: "n",
meta: true,
handler: () => router.push("/workspaces"),
description: "Open workspaces (new note)",
},
{
key: "d",
meta: true,
shift: true,
handler: () => router.push("/dashboard"),
description: "Go to dashboard",
},
{
key: "r",
meta: true,
shift: true,
handler: () => router.push("/reviews"),
description: "Go to reviews",
},
{
key: "Escape",
handler: () => {
const active = document.activeElement as HTMLElement | null;
active?.blur();
},
description: "Dismiss / blur",
},
],
[router],
);
useKeyboardShortcuts(shortcuts);
return null;
}