import { useState } from 'react'; import { useRecoilValue } from 'recoil'; import { useOpenActivityRightDrawer } from '@/activities/hooks/useOpenActivityRightDrawer'; import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys'; import { AppHotkeyScope } from '@/ui/utilities/hotkey/types/AppHotkeyScope'; import { useCommandMenu } from '../hooks/useCommandMenu'; import { commandMenuCommandsState } from '../states/commandMenuCommandsState'; import { isCommandMenuOpenedState } from '../states/isCommandMenuOpenedState'; import { Command, CommandType } from '../types/Command'; import { CommandGroup } from './CommandGroup'; import { CommandMenuItem } from './CommandMenuItem'; import { StyledDialog, StyledEmpty, StyledInput, StyledList, } from './CommandMenuStyles'; export const CommandMenu = () => { const { openCommandMenu, closeCommandMenu } = useCommandMenu(); const openActivityRightDrawer = useOpenActivityRightDrawer(); const isCommandMenuOpened = useRecoilValue(isCommandMenuOpenedState); const [search, setSearch] = useState(''); const commandMenuCommands = useRecoilValue(commandMenuCommandsState); useScopedHotkeys( 'ctrl+k,meta+k', () => { setSearch(''); openCommandMenu(); }, AppHotkeyScope.CommandMenu, [openCommandMenu, setSearch], ); // const { data: peopleData } = useSearchPeopleQuery({ // skip: !isCommandMenuOpened, // variables: { // where: { // OR: [ // { firstName: { contains: search, mode: QueryMode.Insensitive } }, // { lastName: { contains: search, mode: QueryMode.Insensitive } }, // ], // }, // limit: 3, // }, // }); // const people = peopleData?.searchResults ?? []; // const { data: companyData } = useSearchCompanyQuery({ // skip: !isCommandMenuOpened, // variables: { // where: { // OR: [{ name: { contains: search, mode: QueryMode.Insensitive } }], // }, // limit: 3, // }, // }); // const companies = companyData?.searchResults ?? []; // const { data: activityData } = useSearchActivityQuery({ // skip: !isCommandMenuOpened, // variables: { // where: { // OR: [ // { title: { contains: search, mode: QueryMode.Insensitive } }, // { body: { contains: search, mode: QueryMode.Insensitive } }, // ], // }, // limit: 3, // }, // }); // const activities = activityData?.searchResults ?? []; const checkInShortcuts = (cmd: Command, search: string) => { return (cmd.firstHotKey + (cmd.secondHotKey ?? '')) .toLowerCase() .includes(search.toLowerCase()); }; const checkInLabels = (cmd: Command, search: string) => { if (cmd.label) { return cmd.label.toLowerCase().includes(search.toLowerCase()); } return false; }; const matchingNavigateCommand = commandMenuCommands.filter( (cmd) => (search.length > 0 ? checkInShortcuts(cmd, search) || checkInLabels(cmd, search) : true) && cmd.type === CommandType.Navigate, ); const matchingCreateCommand = commandMenuCommands.filter( (cmd) => (search.length > 0 ? checkInShortcuts(cmd, search) || checkInLabels(cmd, search) : true) && cmd.type === CommandType.Create, ); return ( { if (!opened) { closeCommandMenu(); } }} shouldFilter={false} label="Global Command Menu" > No results found. {matchingCreateCommand.map((cmd) => ( ))} {matchingNavigateCommand.map((cmd) => ( ))} {/* {people.map((person) => ( ( )} /> ))} {companies.map((company) => ( ( )} /> ))} {activities.map((activity) => ( openActivityRightDrawer(activity.id)} /> ))} */} ); };