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

Function handleImport

client-next/src/components/bulk-import-dialog.tsx:155–204  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

153 };
154
155 const handleImport = async () => {
156 const toImport = items.filter((item) => item.selected && item.status === "success");
157 if (toImport.length === 0) {
158 setError("No items selected for import.");
159 return;
160 }
161
162 setPhase("importing");
163 setImportProgress({ current: 0, total: toImport.length });
164 setError("");
165
166 let successCount = 0;
167 let failCount = 0;
168
169 for (let i = 0; i < toImport.length; i++) {
170 const item = toImport[i];
171 setImportProgress({ current: i + 1, total: toImport.length });
172
173 try {
174 if (type === "skills") {
175 await saveSkill(
176 item.result!.name!,
177 item.result!.description || "",
178 item.result!.body || item.result!.content || ""
179 );
180 } else {
181 const pluginName = item.result!.name!.endsWith(".js") || item.result!.name!.endsWith(".ts")
182 ? item.result!.name!
183 : `${item.result!.name}.js`;
184 await savePlugin(pluginName, item.result!.content || "");
185 }
186 successCount++;
187 } catch (err: any) {
188 const msg = err.response?.data?.error || err.message || "Unknown error";
189 console.error(`Failed to import ${item.result?.name}:`, msg);
190 failCount++;
191 }
192 }
193
194 if (successCount > 0) {
195 toast.success(`Imported ${successCount}/${toImport.length} ${type}`);
196 onSuccess();
197 }
198 if (failCount > 0) {
199 toast.error(`Failed to import ${failCount} ${type}`);
200 }
201
202 resetForm();
203 setOpen(false);
204 };
205
206 const successItems = items.filter((item) => item.status === "success");
207 const selectedCount = items.filter((item) => item.selected && item.status === "success").length;

Callers

nothing calls this directly

Calls 3

saveSkillFunction · 0.90
savePluginFunction · 0.90
resetFormFunction · 0.70

Tested by

no test coverage detected