import React, { useEffect, useState } from "react"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // icons import { XMarkIcon } from "@heroicons/react/20/solid"; import { MagnifyingGlassIcon } from "@heroicons/react/24/outline"; import { MacCommandIcon } from "components/icons"; // ui import { Input } from "components/ui"; type Props = { isOpen: boolean; setIsOpen: React.Dispatch>; }; const shortcuts = [ { title: "Navigation", shortcuts: [ { keys: "Ctrl,K", description: "To open navigator" }, { keys: "↑", description: "Move up" }, { keys: "↓", description: "Move down" }, { keys: "←", description: "Move left" }, { keys: "→", description: "Move right" }, { keys: "Enter", description: "Select" }, { keys: "Esc", description: "Close" }, ], }, { title: "Common", shortcuts: [ { keys: "P", description: "To create project" }, { keys: "C", description: "To create issue" }, { keys: "Q", description: "To create cycle" }, { keys: "M", description: "To create module" }, { keys: "V", description: "To create view" }, { keys: "D", description: "To create page" }, { keys: "Delete", description: "To bulk delete issues" }, { keys: "H", description: "To open shortcuts guide" }, { keys: "Ctrl,Alt,C", description: "To copy issue url when on issue detail page", }, ], }, ]; const allShortcuts = shortcuts.map((i) => i.shortcuts).flat(1); export const ShortcutsModal: React.FC = ({ isOpen, setIsOpen }) => { const [query, setQuery] = useState(""); const filteredShortcuts = allShortcuts.filter((shortcut) => shortcut.description.toLowerCase().includes(query.trim().toLowerCase()) || query === "" ? true : false ); useEffect(() => { if (!isOpen) setQuery(""); }, [isOpen]); return (
Keyboard Shortcuts
setQuery(e.target.value)} />
{query.trim().length > 0 ? ( filteredShortcuts.length > 0 ? ( filteredShortcuts.map((shortcut) => (

{shortcut.description}

{shortcut.keys.split(",").map((key, index) => ( {key === "Ctrl" ? ( ) : ( {key === "Ctrl" ? : key} )} ))}
)) ) : (

No shortcuts found for{" "} {`"`} {query} {`"`}

) ) : ( shortcuts.map(({ title, shortcuts }) => (

{title}

{shortcuts.map(({ keys, description }, index) => (

{description}

{keys.split(",").map((key, index) => ( {key === "Ctrl" ? ( ) : ( {key === "Ctrl" ? : key} )} ))}
))}
)) )}
); };