import { ContextList, DialogEntry, useContextDialog } from "./ContextDialog"; import { GamePadButtonCode, useShortcuts } from "../scripts/shortcuts"; import { useMatchRoute, useNavigate, useRouter } from "@tanstack/react-router"; import { getCurrentFocusKey } from "@noriginmedia/norigin-spatial-navigation"; import { DoorOpen, Gamepad2, Puzzle, RefreshCcw, Settings, Store } from "lucide-react"; import { systemApi } from "../scripts/clientApi"; import { FOCUS_KEYS } from "../scripts/types"; export default function SelectMenu (data: { rootFocusKey: string; }) { const navigate = useNavigate(); const matchRoute = useMatchRoute(); const router = useRouter(); const options: DialogEntry[] = [ { content: "Home", icon: , action (ctx) { setOpen(false); navigate({ to: "/" }); }, selected: !!matchRoute({ to: '/' }), type: "primary", id: "home-m" }, { content: "Library", icon: , action (ctx) { setOpen(false); navigate({ to: "/games" }); }, selected: !!matchRoute({ to: '/games' }), type: "secondary", id: "library-m" }, { content: "Store", icon: , action (ctx) { setOpen(false); navigate({ to: "/store/tab" }); }, selected: !!matchRoute({ to: '/store/tab' }), type: "info", id: "store-m" }, { content: "Settings", icon: , action (ctx) { setOpen(false); navigate({ to: "/settings/interface" }); }, selected: !!matchRoute({ to: '/settings' }) && !matchRoute({ to: '/settings/plugins' }) && !matchRoute({ to: '/settings/plugin/$source' }), type: "accent", id: "settings-m" }, { content: "Plugins", icon: , action (ctx) { setOpen(false); navigate({ to: "/settings/plugins" }); }, selected: !!matchRoute({ to: '/settings/plugins' }) && !matchRoute({ to: '/settings/plugin/$source' }), type: "accent", id: "plugins-m" }, { content: "Reload", icon: , action (ctx) { setOpen(false); navigation.reload(); }, type: "accent", id: "reload-m" }, { content: "Quit", icon: , action (ctx) { systemApi.api.system.exit.post(); }, type: 'error', id: "quit-m" } ]; const { dialog, setOpen, open } = useContextDialog('select-menu', { content: <>
{router.history.location.pathname}
, className: 'absolute flex flex-col justify-center left-0 top-0 bottom-0 rounded-none max-h-screen', preferredChildFocusKey: FOCUS_KEYS.CONTEXT_DIALOG_OPTION('select-menu', options.find(o => o.selected)?.id ?? '') }); useShortcuts(data.rootFocusKey, () => [{ label: "Menu", side: 'left', button: GamePadButtonCode.Select, action (e) { if (open) { setOpen(false); } else { setOpen(true, getCurrentFocusKey()); } }, }], [open]); return <>{dialog}; }