import {
BookIcon,
DatabaseBackupIcon,
FingerprintIcon,
LayoutDashboard,
LogsIcon,
MailIcon,
Server,
SettingsIcon,
UsersIcon,
} from "lucide-react"
import {
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut,
} from "@/components/ui/command"
import { memo, useEffect, useMemo } from "react"
import { $systems } from "@/lib/stores"
import { getHostDisplayValue, isAdmin, listen } from "@/lib/utils"
import { $router, basePath, navigate, prependBasePath } from "./router"
import { Trans } from "@lingui/react/macro"
import { t } from "@lingui/core/macro"
import { getPagePath } from "@nanostores/router"
export default memo(function CommandPalette({ open, setOpen }: { open: boolean; setOpen: (open: boolean) => void }) {
useEffect(() => {
const down = (e: KeyboardEvent) => {
if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
e.preventDefault()
setOpen(!open)
}
}
return listen(document, "keydown", down)
}, [open, setOpen])
return useMemo(() => {
const systems = $systems.get()
const SettingsShortcut = (
Settings
)
const AdminShortcut = (
Admin
)
return (
No results found.
{systems.length > 0 && (
<>
{systems.map((system) => (
{
navigate(getPagePath($router, "system", { name: system.name }))
setOpen(false)
}}
>
{system.name}
{getHostDisplayValue(system)}
))}
>
)}
{
navigate(basePath)
setOpen(false)
}}
>
Dashboard
Page
{
navigate(getPagePath($router, "settings", { name: "general" }))
setOpen(false)
}}
>
Settings
{SettingsShortcut}
{
navigate(getPagePath($router, "settings", { name: "notifications" }))
setOpen(false)
}}
>
Notifications
{SettingsShortcut}
{
navigate(getPagePath($router, "settings", { name: "tokens" }))
setOpen(false)
}}
>
Tokens & Fingerprints
{SettingsShortcut}
{
window.location.href = "https://beszel.dev/guide/what-is-beszel"
}}
>
Documentation
beszel.dev
{isAdmin() && (
<>
{
setOpen(false)
window.open(prependBasePath("/_/"), "_blank")
}}
>
Users
{AdminShortcut}
{
setOpen(false)
window.open(prependBasePath("/_/#/logs"), "_blank")
}}
>
Logs
{AdminShortcut}
{
setOpen(false)
window.open(prependBasePath("/_/#/settings/backups"), "_blank")
}}
>
Backups
{AdminShortcut}
{
setOpen(false)
window.open(prependBasePath("/_/#/settings/mail"), "_blank")
}}
>
SMTP settings
{AdminShortcut}
>
)}
)
}, [open])
})