import { useEffect, useState } from "preact/hooks"; import { LANG, t } from "../../i18n"; import { api, apiErrorText } from "../../features/customize/api"; import { custTab } from "../../features/customize/actions"; import { nestedEditor } from "../../features/customize/state"; import { skillReadinessNoteText } from "../../features/customize/environment"; import { asList, asString, confirmAction, dropSkillsCatalog, hint, } from "../../features/customize/host"; import { scheduleTimeout } from "../../features/customize/timers"; import { useAlive, useTimerLease } from "./use-timer-lease"; import { Icon } from "./icons"; function skillVersionPath(name: string, scope: string, projectId: string | null): string { const encodedName = encodeURIComponent(name); if (scope === "project") { if (!projectId) throw new Error("project scope is unavailable"); return `/projects/${encodeURIComponent(projectId)}/skills/${encodedName}`; } return `/skills/${encodedName}`; } export function NestedEditor() { const editor = nestedEditor.value; if (!editor) return null; return (
{ if (e.target === e.currentTarget) nestedEditor.value = null; }} >
{editor.kind === "skill" ? : null} {editor.kind === "skill-import" ? : null} {editor.kind === "skill-history" ? ( ) : null} {editor.kind === "specialist" ? : null} {editor.kind === "connector" ? : null} {editor.kind === "job" ? : null}
); } function titleFor(editor: NonNullable): string { if (editor.kind === "skill") return editor.name ? t("skill.editTitle", editor.name) : t("skill.newTitle"); if (editor.kind === "skill-import") return t("skill.importTitle"); if (editor.kind === "skill-history") return t("skill.historyTitle", editor.name); if (editor.kind === "specialist") return editor.name ? t("specialist.editTitle", editor.name) : t("specialist.newTitle"); if (editor.kind === "connector") return t("cust.connectors.editTitle", asString(editor.connector.name)); if (editor.kind === "job") return t("job.outputTitle", editor.id); return ""; } function SkillForm({ name }: { name: string | null }) { const alive = useAlive(); const [nm, setNm] = useState(name || ""); const [desc, setDesc] = useState(""); const [body, setBody] = useState(""); const [saving, setSaving] = useState(false); useEffect(() => { if (!name) return; void (async () => { try { const cur = await api(`/skills/${encodeURIComponent(name)}`); if (!alive()) return; setNm(asString(cur.name, name)); setDesc(asString(cur.description)); setBody(asString(cur.body)); } catch { /* keep blanks */ } })(); }, [alive, name]); return (
setNm((e.target as HTMLInputElement).value)} /> setDesc((e.target as HTMLInputElement).value)} />