()
| 72 | }, [type, name, isNew, router]); |
| 73 | |
| 74 | const handleSave = async () => { |
| 75 | if (!type || !name) return; |
| 76 | |
| 77 | try { |
| 78 | setSaving(true); |
| 79 | if (type === "skills") { |
| 80 | if (!description.trim()) { |
| 81 | toast.error("Description is required for skills"); |
| 82 | return; |
| 83 | } |
| 84 | const targetName = currentName.trim() || name; |
| 85 | let finalContent = content; |
| 86 | if (finalContent.includes("<description>")) { |
| 87 | finalContent = finalContent.replace(/<description>[\s\S]*?<\/description>/, `<description>${description}</description>`); |
| 88 | } else { |
| 89 | finalContent = `<description>\n${description}\n</description>\n\n${finalContent}`; |
| 90 | } |
| 91 | |
| 92 | await saveSkill(targetName, description, finalContent); |
| 93 | |
| 94 | if (targetName !== name && !isNew) { |
| 95 | await deleteSkill(name); |
| 96 | router.replace(`/editor?type=skills&name=${encodeURIComponent(targetName)}`); |
| 97 | } |
| 98 | } else if (type === "commands") { |
| 99 | const targetName = currentName.trim() || name; |
| 100 | await saveCommand(targetName, content); |
| 101 | if (targetName !== name && !isNew) { |
| 102 | await deleteCommand(name); |
| 103 | router.replace(`/editor?type=commands&name=${encodeURIComponent(targetName)}`); |
| 104 | } |
| 105 | } else { |
| 106 | await savePlugin(name, content); |
| 107 | } |
| 108 | toast.success(`Saved ${currentName || name}`); |
| 109 | } catch { |
| 110 | toast.error("Failed to save file"); |
| 111 | } finally { |
| 112 | setSaving(false); |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | const handleBack = () => { |
| 117 | router.push(`/${type}`); |
nothing calls this directly
no test coverage detected