import { useMemo, useState } from "react"; import { useScripts } from "../../api/hooks.js"; import { ScriptIcon } from "../ScriptIcon.jsx"; import { scriptTags } from "../../lib/script.js"; export function AddScriptDialog({ open, onClose, onPick }) { const { data: scripts = [], isLoading } = useScripts(); const [q, setQ] = useState(""); const filtered = useMemo(() => { const term = q.trim().toLowerCase(); const list = scripts.map((s) => ({ name: typeof s === "string" ? s : s.name, description: typeof s === "string" ? "" : s.meta?.description ?? "", meta: typeof s === "string" ? null : s.meta, metaError: typeof s === "string" ? null : s.metaError, hasIcon: typeof s === "string" ? undefined : s.hasIcon, tags: typeof s === "string" ? [] : scriptTags(s.meta), })); if (!term) return list; return list.filter( (s) => s.name.toLowerCase().includes(term) || s.description.toLowerCase().includes(term) || s.tags.some((t) => t.toLowerCase().includes(term)), ); }, [scripts, q]); if (!open) return null; return (

Add script

setQ(e.target.value)} autoFocus />
); }