MCPcopy Create free account
hub / github.com/Microck/opencode-studio / AddSkillDialog

Function AddSkillDialog

client-next/src/components/add-skill-dialog.tsx:92–321  ·  view source on GitHub ↗
({ onSuccess }: AddSkillDialogProps)

Source from the content-addressed store, hash-verified

90}
91
92export function AddSkillDialog({ onSuccess }: AddSkillDialogProps) {
93 const [open, setOpen] = useState(false);
94 const [name, setName] = useState("");
95 const [description, setDescription] = useState("");
96 const [content, setContent] = useState(SKILL_TEMPLATE);
97 const [error, setError] = useState("");
98 const [loading, setLoading] = useState(false);
99 const [fetching, setFetching] = useState(false);
100 const [urlInput, setUrlInput] = useState("");
101
102 const resetForm = () => {
103 setName("");
104 setDescription("");
105 setContent(SKILL_TEMPLATE);
106 setError("");
107 setUrlInput("");
108 };
109
110 const handleFetchUrl = async () => {
111 if (!urlInput.trim()) return;
112
113 if (!isUrl(urlInput)) {
114 setError("Please enter a valid URL (http:// or https://)");
115 return;
116 }
117
118 try {
119 setFetching(true);
120 setError("");
121 const result = await fetchUrl(urlInput.trim());
122
123 const parsed = parseFrontmatter(result.content);
124 if (parsed.name || parsed.description) {
125 if (!name && parsed.name) setName(parsed.name);
126 if (!description && parsed.description) setDescription(parsed.description);
127 setContent(parsed.body);
128 } else {
129 setContent(result.content);
130 if (!name) {
131 const extractedName = extractNameFromUrl(urlInput);
132 if (extractedName) setName(extractedName);
133 }
134 }
135
136 toast.success("Fetched content from URL");
137 setUrlInput("");
138 } catch (err) {
139 setError(err instanceof Error ? err.message : "Failed to fetch URL");
140 } finally {
141 setFetching(false);
142 }
143 };
144
145 const handlePaste = async (e: React.ClipboardEvent<HTMLInputElement>) => {
146 const pastedText = e.clipboardData.getData('text');
147 if (isUrl(pastedText)) {
148 e.preventDefault();
149 setUrlInput(pastedText);

Callers

nothing calls this directly

Calls 1

resetFormFunction · 0.70

Tested by

no test coverage detected