|
|
@ -8,6 +8,7 @@ import VideoIcon from '../../icons/video.svg'; |
|
|
|
import { httpGet } from '../../lib/http'; |
|
|
|
import { httpGet } from '../../lib/http'; |
|
|
|
import { useKeydown } from '../../hooks/use-keydown'; |
|
|
|
import { useKeydown } from '../../hooks/use-keydown'; |
|
|
|
import { isLoggedIn } from '../../lib/jwt'; |
|
|
|
import { isLoggedIn } from '../../lib/jwt'; |
|
|
|
|
|
|
|
import { useOutsideClick } from '../../hooks/use-outside-click'; |
|
|
|
|
|
|
|
|
|
|
|
type PageType = { |
|
|
|
type PageType = { |
|
|
|
url: string; |
|
|
|
url: string; |
|
|
@ -45,6 +46,7 @@ function shouldShowPage(page: PageType) { |
|
|
|
|
|
|
|
|
|
|
|
export function CommandMenu() { |
|
|
|
export function CommandMenu() { |
|
|
|
const inputRef = useRef<HTMLInputElement>(null); |
|
|
|
const inputRef = useRef<HTMLInputElement>(null); |
|
|
|
|
|
|
|
const modalRef = useRef<HTMLInputElement>(null); |
|
|
|
const [isActive, setIsActive] = useState(false); |
|
|
|
const [isActive, setIsActive] = useState(false); |
|
|
|
const [allPages, setAllPages] = useState<PageType[]>([]); |
|
|
|
const [allPages, setAllPages] = useState<PageType[]>([]); |
|
|
|
const [searchResults, setSearchResults] = useState<PageType[]>(defaultPages); |
|
|
|
const [searchResults, setSearchResults] = useState<PageType[]>(defaultPages); |
|
|
@ -55,6 +57,10 @@ export function CommandMenu() { |
|
|
|
setIsActive(true); |
|
|
|
setIsActive(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useOutsideClick(modalRef, () => { |
|
|
|
|
|
|
|
setIsActive(false); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (!isActive || !inputRef.current) { |
|
|
|
if (!isActive || !inputRef.current) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -105,7 +111,7 @@ export function CommandMenu() { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="fixed left-0 right-0 top-0 z-50 flex h-full justify-center overflow-y-auto overflow-x-hidden bg-black/50"> |
|
|
|
<div className="fixed left-0 right-0 top-0 z-50 flex h-full justify-center overflow-y-auto overflow-x-hidden bg-black/50"> |
|
|
|
<div className="relative top-0 h-full w-full max-w-lg p-2 sm:top-20 md:h-auto"> |
|
|
|
<div className="relative top-0 h-full w-full max-w-lg p-2 sm:top-20 md:h-auto"> |
|
|
|
<div className="relative rounded-lg bg-white shadow"> |
|
|
|
<div className="relative rounded-lg bg-white shadow" ref={modalRef}> |
|
|
|
<input |
|
|
|
<input |
|
|
|
ref={inputRef} |
|
|
|
ref={inputRef} |
|
|
|
autofocus={true} |
|
|
|
autofocus={true} |
|
|
@ -168,10 +174,7 @@ export function CommandMenu() { |
|
|
|
<span class="mr-2 text-gray-400">{page.group}</span> |
|
|
|
<span class="mr-2 text-gray-400">{page.group}</span> |
|
|
|
)} |
|
|
|
)} |
|
|
|
{page.icon && ( |
|
|
|
{page.icon && ( |
|
|
|
<img |
|
|
|
<img src={page.icon} class="mr-2 h-4 w-4" /> |
|
|
|
src={page.icon} |
|
|
|
|
|
|
|
class="mr-2 h-4 w-4" |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
)} |
|
|
|
)} |
|
|
|
{page.title} |
|
|
|
{page.title} |
|
|
|
</a> |
|
|
|
</a> |
|
|
|