import React from 'react'; import { useNavigate, useRouter } from '@tanstack/react-router'; import { IconArrowRightDashed, IconChevronRight, IconDeviceLaptop, IconMoon, IconSun } from '@tabler/icons-react'; import { useTranslation } from 'react-i18next'; import { useSearch } from '@/context/search-context'; import { useTheme } from '@/context/theme-context'; import { CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, } from '@/components/ui/command'; import { useSidebarData } from '../sidebar'; import { ScrollArea } from './ui/scroll-area'; export function CommandMenu() { const router = useRouter(); const { setTheme } = useTheme(); const { open, setOpen } = useSearch(); const sidebarData = useSidebarData(); const { t } = useTranslation(); // Don't render if router is not available if (!router) { return null; } const navigate = useNavigate(); const runCommand = React.useCallback( (command: () => unknown) => { setOpen(false); command(); }, [setOpen] ); return ( {t('command.noResults')} {sidebarData.navGroups.map((group) => ( {group.items.map((navItem, i) => { if (navItem.url) return ( { runCommand(() => navigate({ to: navItem.url })); }} >
{navItem.title}
); return navItem.items?.map((subItem, i) => ( { runCommand(() => navigate({ to: subItem.url })); }} >
{navItem.title} {subItem.title}
)); })}
))} runCommand(() => setTheme('light'))}> {t('theme.light')} runCommand(() => setTheme('dark'))}> {t('theme.dark')} runCommand(() => setTheme('system'))}> {t('theme.system')}
); }