import { Modal, ModalWrapper } from '@/ui/modal'; import { StyledContent, StyledModalHeader, StyledModalFooter, StyledModalDivider, StyledShortcut, } from './style'; import { Input } from './Input'; import { Results } from './Results'; import { Footer } from './Footer'; import { Command } from 'cmdk'; import { useEffect, useState } from 'react'; import { useModal } from '@/providers/GlobalModalProvider'; import { getUaHelper } from '@/utils'; import { useAppState } from '@/providers/app-state-provider'; type TransitionsModalProps = { open: boolean; onClose: () => void; }; const isMac = () => { return getUaHelper().isMacOs; }; export const QuickSearch = ({ open, onClose }: TransitionsModalProps) => { const { currentWorkspace } = useAppState(); const [query, setQuery] = useState(''); const [loading, setLoading] = useState(true); const [showCreatePage, setShowCreatePage] = useState(true); const { triggerQuickSearchModal } = useModal(); // Add ‘⌘+K’ shortcut keys as switches useEffect(() => { const down = (e: KeyboardEvent) => { if ((e.key === 'k' && e.metaKey) || (e.key === 'k' && e.ctrlKey)) { const selection = window.getSelection(); if (selection?.toString()) { triggerQuickSearchModal(false); return; } if (selection?.isCollapsed) { triggerQuickSearchModal(!open); } } }; if (!open) { setQuery(''); } document.addEventListener('keydown', down, { capture: true }); return () => document.removeEventListener('keydown', down, { capture: true }); }, [open, triggerQuickSearchModal]); return ( { if ( e.key === 'ArrowDown' || e.key === 'ArrowUp' || e.key === 'ArrowLeft' || e.key === 'ArrowRight' ) { e.stopPropagation(); } }} > {isMac() ? '⌘ + K' : 'Ctrl + K'} {currentWorkspace?.isPublish ? ( <> ) : showCreatePage ? ( <>