import { useT } from "@agent-native/core/client/i18n"; import { CommandMenu } from "@agent-native/core/client/navigation"; import { IconHierarchy2, IconInbox, IconStar, IconSend, IconFileText, IconArchive, IconTrash, IconSearch, IconPencil, IconMoon, IconSun, IconRefresh, IconCornerUpLeft, IconShieldExclamation, IconBan, IconBellOff, IconPhotoOff, IconPhoto, IconEye, IconAlarm, IconCheck, } from "@tabler/icons-react"; import { useTheme } from "next-themes"; import { useNavigate } from "react-router"; import { useSettings, useUpdateSettings } from "@/hooks/use-emails"; import { getResolvedTheme } from "@/lib/theme"; import changelog from "../../../CHANGELOG.md?raw"; interface CommandPaletteProps { open: boolean; onOpenChange: (open: boolean) => void; onCompose: () => void; onReply?: () => void; onSnooze?: () => void; onSpam?: () => void; onBlockSender?: () => void; onMuteThread?: () => void; /** Whether there is a focused/selected email for contextual actions */ hasEmail?: boolean; } const navCommands = [ { labelKey: "commandPalette.goToInbox", icon: IconInbox, route: "/inbox", shortcut: "G I", }, { labelKey: "commandPalette.goToStarred", icon: IconStar, route: "/starred", shortcut: "G S", }, { labelKey: "commandPalette.goToSent", icon: IconSend, route: "/sent", shortcut: "G T", }, { labelKey: "commandPalette.goToDrafts", icon: IconFileText, route: "/drafts", shortcut: "G D", }, { labelKey: "commandPalette.goToArchive", icon: IconArchive, route: "/archive", shortcut: "G A", }, { labelKey: "commandPalette.goToTrash", icon: IconTrash, route: "/trash" }, { labelKey: "settings.openAgentSettings", icon: IconHierarchy2, route: "/agent", }, ]; export function CommandPalette({ open, onOpenChange, onCompose, onReply, onSnooze, onSpam, onBlockSender, onMuteThread, hasEmail, }: CommandPaletteProps) { const t = useT(); const navigate = useNavigate(); const { resolvedTheme, setTheme } = useTheme(); const isDark = getResolvedTheme(resolvedTheme) === "dark"; const { data: settings } = useSettings(); const updateSettings = useUpdateSettings(); const imagePolicy = settings?.imagePolicy ?? "show"; return ( {t("commandPalette.compose")} C {onReply && ( {t("commandPalette.reply")} R )} {onSnooze && ( {t("commandPalette.snooze")} H )} navigate(`/all?q=`)} keywords={["search", "find"]} > {t("commandPalette.search")} / window.location.reload()} keywords={["refresh", "reload"]} > {t("commandPalette.refresh")} {onSpam && ( {t("commandPalette.reportSpam")} )} {onBlockSender && ( {t("commandPalette.reportSpamBlock")} )} {onMuteThread && ( {t("commandPalette.muteThread")} )} {navCommands.map((cmd) => ( navigate(cmd.route)} keywords={[t(cmd.labelKey).toLowerCase()]} > {t(cmd.labelKey)} {cmd.shortcut && ( {cmd.shortcut} )} ))} updateSettings.mutate({ imagePolicy: "show" })} keywords={["images", "show"]} > {t("commandPalette.imagesShowAll")} {imagePolicy === "show" && ( )} updateSettings.mutate({ imagePolicy: "block-trackers" }) } keywords={["images", "trackers", "privacy"]} > {t("commandPalette.imagesBlockTrackers")} {imagePolicy === "block-trackers" && ( )} updateSettings.mutate({ imagePolicy: "block-all" })} keywords={["images", "block", "privacy"]} > {t("commandPalette.imagesBlockAll")} {imagePolicy === "block-all" && ( )} setTheme( getResolvedTheme(resolvedTheme) === "dark" ? "light" : "dark", ) } keywords={["theme", "dark", "light", "mode"]} > {isDark ? ( ) : ( )} {isDark ? t("commandPalette.toggleLight") : t("commandPalette.toggleDark")} ); }