Skip to content

Commit 167ae13

Browse files
committed
refactor: remove iife
1 parent 2fb931c commit 167ae13

2 files changed

Lines changed: 51 additions & 53 deletions

File tree

packages/slice-machine/src/features/customTypes/customTypesBuilder/ImportSlicesFromLibraryModal/ImportSlicesFromLibraryModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export function ImportSlicesFromLibraryModal(
254254
onValueChange={setGithubUrl}
255255
/>
256256
<Button
257-
onClick={() => handleImportFromGithub(githubUrl)}
257+
onClick={() => void handleImportFromGithub(githubUrl)}
258258
disabled={!githubUrl.trim() || isLoadingSlices}
259259
loading={isLoadingSlices}
260260
color="purple"

packages/slice-machine/src/features/customTypes/customTypesBuilder/ImportSlicesFromLibraryModal/hooks/useImportSlicesFromGithub.ts

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,69 +19,67 @@ export function useImportSlicesFromGithub() {
1919
};
2020

2121
const handleImportFromGithub = (githubUrl: string) => {
22-
void (async () => {
23-
try {
24-
setIsLoadingSlices(true);
25-
26-
const { owner, repo } = parseGithubUrl(githubUrl);
27-
if (!owner || !repo) {
28-
toast.error("Invalid GitHub URL format");
29-
setIsLoadingSlices(false);
30-
return;
31-
}
32-
33-
const branch = await getDefaultBranch({ owner, repo });
34-
35-
let libraries: string[] | undefined;
36-
37-
try {
38-
libraries = await getSliceLibraries({ owner, repo, branch });
39-
} catch (error) {
40-
console.error("Failed to fetch slicemachine.config.json:", error);
41-
toast.error(
42-
`Failed to fetch slicemachine.config.json: ${
43-
error instanceof Error ? error.message : "Unknown error"
44-
}`,
45-
);
46-
setIsLoadingSlices(false);
47-
return;
48-
}
22+
try {
23+
setIsLoadingSlices(true);
4924

50-
if (libraries.length === 0) {
51-
console.warn("No libraries were found in the SM config.");
52-
setIsLoadingSlices(false);
53-
toast.error("No libraries were found in the SM config.");
54-
return;
55-
}
25+
const { owner, repo } = parseGithubUrl(githubUrl);
26+
if (!owner || !repo) {
27+
toast.error("Invalid GitHub URL format");
28+
setIsLoadingSlices(false);
29+
return;
30+
}
5631

57-
const fetchedSlices = await fetchSlicesFromLibraries({
58-
owner,
59-
repo,
60-
branch,
61-
libraries,
62-
});
32+
const branch = await getDefaultBranch({ owner, repo });
6333

64-
if (fetchedSlices.length === 0) {
65-
toast.error("Error fetching slices from the repository");
66-
setIsLoadingSlices(false);
67-
return;
68-
}
34+
let libraries: string[] | undefined;
6935

70-
setSlices(fetchedSlices);
71-
setIsLoadingSlices(false);
72-
toast.success(
73-
`Found ${fetchedSlices.length} slice(s) from ${libraries.length} library/libraries`,
74-
);
36+
try {
37+
libraries = await getSliceLibraries({ owner, repo, branch });
7538
} catch (error) {
76-
console.error("Error importing from GitHub:", error);
39+
console.error("Failed to fetch slicemachine.config.json:", error);
7740
toast.error(
78-
`Error importing from GitHub: ${
41+
`Failed to fetch slicemachine.config.json: ${
7942
error instanceof Error ? error.message : "Unknown error"
8043
}`,
8144
);
8245
setIsLoadingSlices(false);
46+
return;
8347
}
84-
})();
48+
49+
if (libraries.length === 0) {
50+
console.warn("No libraries were found in the SM config.");
51+
setIsLoadingSlices(false);
52+
toast.error("No libraries were found in the SM config.");
53+
return;
54+
}
55+
56+
const fetchedSlices = await fetchSlicesFromLibraries({
57+
owner,
58+
repo,
59+
branch,
60+
libraries,
61+
});
62+
63+
if (fetchedSlices.length === 0) {
64+
toast.error("Error fetching slices from the repository");
65+
setIsLoadingSlices(false);
66+
return;
67+
}
68+
69+
setSlices(fetchedSlices);
70+
setIsLoadingSlices(false);
71+
toast.success(
72+
`Found ${fetchedSlices.length} slice(s) from ${libraries.length} library/libraries`,
73+
);
74+
} catch (error) {
75+
console.error("Error importing from GitHub:", error);
76+
toast.error(
77+
`Error importing from GitHub: ${
78+
error instanceof Error ? error.message : "Unknown error"
79+
}`,
80+
);
81+
setIsLoadingSlices(false);
82+
}
8583
};
8684

8785
return {

0 commit comments

Comments
 (0)