import { Spotlight } from "@mantine/spotlight"; import { getSafeAppHref, SAFE_NEW_TAB_REL } from "@homarr/common"; import type { TranslationObject } from "@homarr/translation"; import { Link } from "@homarr/ui"; import type { SearchGroup } from "../../../lib/group"; import type { inferSearchInteractionOptions } from "../../../lib/interaction"; import { selectAction, spotlightStore } from "../../../spotlight-store"; import classes from "./action-item.module.css"; interface SpotlightGroupActionItemProps> { option: TOption; query: string; setQuery: (query: string) => void; setMode: (mode: keyof TranslationObject["search"]["mode"]) => void; setChildrenOptions: (options: inferSearchInteractionOptions<"children">) => void; group: SearchGroup; } export const SpotlightGroupActionItem = >({ group, query, setQuery, setMode, setChildrenOptions, option, }: SpotlightGroupActionItemProps) => { const interaction = group.useInteraction(option, query); const unavailable = "unavailable" in option && option.unavailable === true; // Avoid passing React's special `key` prop via spread const { key: _reactKey, ...optionProps } = option as unknown as { key?: unknown } & Record; const safeHref = interaction.type === "link" ? getSafeAppHref(interaction.href) : undefined; const renderRoot = interaction.type === "link" && safeHref ? (props: Record) => { return ( ); } : undefined; const handleClickAsync = async () => { if (interaction.type === "javaScript") { await interaction.onSelect(); } else if (interaction.type === "setQuery") { setQuery(interaction.query); setTimeout(() => selectAction(0, spotlightStore)); } else if (interaction.type === "mode") { if (interaction.query !== undefined) { setQuery(interaction.query); } setMode(interaction.mode); } else if (interaction.type === "children") { setChildrenOptions(interaction); } }; return ( ); };