Skip to content

Commit 1e6f5ac

Browse files
committed
fix: edit logic
1 parent 09f7a3d commit 1e6f5ac

File tree

2 files changed

+69
-31
lines changed

2 files changed

+69
-31
lines changed

src/components/project/index.tsx

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ const Template = () => {
347347
compileLoading,
348348
deployLoading,
349349
activateLoading,
350+
setProject,
350351
} = useStore(
351352
useShallow((state) => ({
352353
client: state.global.client,
@@ -358,6 +359,7 @@ const Template = () => {
358359
compileLoading: state.compile.loading,
359360
deployLoading: state.deploy.loading,
360361
activateLoading: state.activate.loading,
362+
setProject: state.project.setProject,
361363
}))
362364
);
363365
const isLoading = compileLoading || deployLoading || activateLoading;
@@ -383,40 +385,70 @@ const Template = () => {
383385
}
384386
};
385387

386-
if (await isExists(template)) {
387-
await client.terminal.log({
388-
type: "error",
389-
value: `The folder ${template} already exists`,
388+
try {
389+
if (await isExists(template)) {
390+
await client.terminal.log({
391+
type: "error",
392+
value: `The folder ${template} already exists`,
393+
});
394+
return;
395+
}
396+
397+
const res = await axios.request({
398+
method: "GET",
399+
url: `https://api.welldonestudio.io/compiler/s3Proxy?bucket=code-template&fileKey=arbitrum/${template}.zip`,
400+
responseType: "arraybuffer",
401+
responseEncoding: "null",
390402
});
391-
return;
392-
}
393403

394-
const res = await axios.request({
395-
method: "GET",
396-
url: `https://api.welldonestudio.io/compiler/s3Proxy?bucket=code-template&fileKey=arbitrum/` + template + ".zip",
397-
responseType: "arraybuffer",
398-
responseEncoding: "null",
399-
});
404+
const jsZip = new JSZip();
405+
const zip = await jsZip.loadAsync(res.data);
400406

401-
const jsZip = new JSZip();
402-
const zip = await jsZip.loadAsync(res.data);
407+
let content: any;
408+
try {
409+
Object.keys(zip.files).map(async (key) => {
410+
log.debug(`@@@ key=${key}`);
411+
if (zip.files[key].dir) {
412+
await client?.fileManager.mkdir("browser/arbitrum/" + key);
413+
} else if (!key.startsWith("_") && key !== template + "/.DS_Store") {
414+
content = await zip.file(key)?.async("string");
415+
await client?.fileManager.writeFile("browser/arbitrum/" + key, content);
416+
}
417+
});
418+
await fetchProjects();
403419

404-
let content: any;
405-
try {
406-
Object.keys(zip.files).map(async (key) => {
407-
log.debug(`@@@ key=${key}`);
408-
if (zip.files[key].dir) {
409-
await client?.fileManager.mkdir("browser/arbitrum/" + key);
410-
} else if (!key.startsWith("_") && key !== template + "/.DS_Store") {
411-
content = await zip.file(key)?.async("string");
412-
await client?.fileManager.writeFile("browser/arbitrum/" + key, content);
413-
}
414-
});
415-
await fetchProjects();
420+
// 템플릿 생성 후 해당 프로젝트를 자동으로 선택
421+
const projectPath = `arbitrum/${template}`;
422+
setProject(projectPath);
416423

417-
await client.terminal.log({ type: "info", value: template + " is created successfully." });
418-
} catch (e) {
419-
log.error(e);
424+
await client.terminal.log({ type: "info", value: template + " is created successfully." });
425+
} catch (e) {
426+
log.error(e);
427+
await client.terminal.log({
428+
type: "error",
429+
value: "Failed to extract template files. Please try again.",
430+
});
431+
}
432+
} catch (error) {
433+
log.error(error);
434+
if (axios.isAxiosError(error)) {
435+
if (error.response?.status === 404) {
436+
await client.terminal.log({
437+
type: "error",
438+
value: `Template "${template}" not found. Please check the template name.`,
439+
});
440+
} else {
441+
await client.terminal.log({
442+
type: "error",
443+
value: `Failed to download template. Error: ${error.message}`,
444+
});
445+
}
446+
} else {
447+
await client.terminal.log({
448+
type: "error",
449+
value: "An unexpected error occurred while creating the template.",
450+
});
451+
}
420452
}
421453
};
422454

@@ -495,6 +527,9 @@ const TargetProject = () => {
495527
);
496528
const isLoading = compileLoading || deployLoading || activateLoading;
497529

530+
console.log("@@@ target project", project);
531+
console.log("@@@ target projects", projects);
532+
498533
const handleTargetProjectOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
499534
setProject(event.target.value);
500535
};

src/zustand/project.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,15 @@ export const createProjectStore: StateCreator<ProjectState & GlobalState, [], []
174174

175175
try {
176176
await findTomlFileRecursively("browser/arbitrum");
177-
const project = get().project.template.data ? `arbitrum/${get().project.template.data}` : projects[0];
177+
const selectedTemplate = get().project.template.data;
178+
const templateProjectPath = selectedTemplate ? `arbitrum/${selectedTemplate}` : null;
179+
const projectExists = templateProjectPath ? projects.includes(templateProjectPath) : false;
180+
178181
set(
179182
produce((state: ProjectState) => {
180183
state.project.projects.loading = false;
181184
state.project.projects.data = projects;
182-
state.project.project.data = project;
185+
state.project.project.data = projectExists ? templateProjectPath : projects.length > 0 ? projects[0] : null;
183186
})
184187
);
185188
} catch (error) {

0 commit comments

Comments
 (0)