MCPcopy Create free account
hub / github.com/alanagoyal/docbase / CommandMenu

Function CommandMenu

components/command-menu.tsx:32–133  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30};
31
32export function CommandMenu() {
33 const router = useRouter();
34 const [open, setOpen] = useState(false);
35 const { theme, setTheme } = useTheme();
36
37 const navigateAndCloseDialog = useCallback(
38 (path: string) => {
39 router.push(path);
40 setOpen(false);
41 },
42 [router]
43 );
44
45 const handleSignOut = async () => {
46 const supabase = createClient();
47 const { error } = await supabase.auth.signOut();
48 if (error) clientLogger.error('Sign out error', { error });
49 router.push("/login");
50 router.refresh();
51 };
52
53 useEffect(() => {
54 const down = (e: KeyboardEvent) => {
55 if (!isTyping()) {
56 if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
57 e.preventDefault();
58 setOpen((open) => !open);
59 } else {
60 const pressedKey = e.key.toLowerCase();
61 const allItems = [...menuItems, ...mainNavItems];
62 const matchedItem = allItems.find(item => item.shortcut.toLowerCase() === pressedKey);
63
64 if (matchedItem) {
65 e.preventDefault();
66 if (matchedItem.href) {
67 navigateAndCloseDialog(matchedItem.href);
68 } else if (matchedItem.action === 'theme') {
69 setTheme(theme === "light" ? "dark" : "light");
70 } else if (matchedItem.action === 'logout') {
71 handleSignOut();
72 }
73 }
74 }
75 }
76 };
77
78 document.addEventListener("keydown", down);
79 return () => document.removeEventListener("keydown", down);
80 }, [router, theme, setTheme, navigateAndCloseDialog, handleSignOut]);
81
82 const handleItemClick = (item: any) => {
83 if (item.href) {
84 navigateAndCloseDialog(item.href);
85 } else if (item.action === 'theme') {
86 setTheme(theme === 'light' ? 'dark' : 'light');
87 setOpen(false);
88 } else if (item.action === 'logout') {
89 handleSignOut();

Callers

nothing calls this directly

Calls 1

handleItemClickFunction · 0.85

Tested by

no test coverage detected