()
| 14 | import { PageHelp } from "@/components/page-help"; |
| 15 | |
| 16 | function EditorContent() { |
| 17 | const searchParams = useSearchParams(); |
| 18 | const router = useRouter(); |
| 19 | const type = searchParams.get("type") as "skills" | "plugins" | "commands" | null; |
| 20 | const name = searchParams.get("name"); |
| 21 | const isNew = searchParams.get("new") === "true"; |
| 22 | |
| 23 | const [content, setContent] = useState(""); |
| 24 | const [description, setDescription] = useState(""); |
| 25 | const [currentName, setCurrentName] = useState(""); |
| 26 | const [loading, setLoading] = useState(true); |
| 27 | const [saving, setSaving] = useState(false); |
| 28 | |
| 29 | useEffect(() => { |
| 30 | if (!type || !name) { |
| 31 | router.push("/skills"); |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | if (isNew) { |
| 36 | const defaultContent = type === "skills" ? "## When to Use\n\n## Instructions\n\n" : |
| 37 | type === "commands" ? "Instructions:\n" : |
| 38 | "// New Plugin\n\n"; |
| 39 | setContent(defaultContent); |
| 40 | setCurrentName(name); |
| 41 | setLoading(false); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | const loadFile = async () => { |
| 46 | try { |
| 47 | setLoading(true); |
| 48 | if (type === "skills") { |
| 49 | const data = await getSkill(name); |
| 50 | setContent(data.content); |
| 51 | const match = data.content.match(/<description>([\s\S]*?)<\/description>/); |
| 52 | setDescription(data.description || (match ? match[1].trim() : "")); |
| 53 | setCurrentName(name); |
| 54 | } else if (type === "commands") { |
| 55 | const data = await getCommand(name); |
| 56 | setContent(data.template); |
| 57 | setCurrentName(name); |
| 58 | } else { |
| 59 | const data = await getPlugin(name); |
| 60 | setContent(data.content); |
| 61 | setCurrentName(name); |
| 62 | } |
| 63 | } catch { |
| 64 | toast.error("Failed to load file"); |
| 65 | router.back(); |
| 66 | } finally { |
| 67 | setLoading(false); |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | loadFile(); |
| 72 | }, [type, name, isNew, router]); |
| 73 |
nothing calls this directly
no test coverage detected