Skip to content

Commit 3267a78

Browse files
committed
Dynamic import swal modules
1 parent 84691bd commit 3267a78

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

src/components/pages/about/Project.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IProject } from "@/assets/state/projects";
22
import LinkButton from "@/components/controls/LinkButton";
3-
import { modal } from "@/utils/swal";
3+
44
import { useCallback } from "react";
55

66
export interface ProjectProps extends IProject {
@@ -9,7 +9,9 @@ export interface ProjectProps extends IProject {
99

1010
const Project = ({ title, description, thumbnail, thumbnailAlt, href, linkText, linkRel }: ProjectProps) => {
1111

12-
const onImageClick = useCallback(() => {
12+
const onImageClick = useCallback(async () => {
13+
const { modal } = await import("@/utils/swal");
14+
1315
modal.fire({
1416
title: thumbnailAlt,
1517
html: <>

src/utils/ssr.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
export const isSSR = typeof window === "undefined";
2-
export const isBrowser = !isSSR;
3-
4-
export const asImport = <Props>(component: React.ComponentType<Props>) => {
5-
return () => Promise.resolve({ "default": component });
6-
};
2+
export const isBrowser = !isSSR;

src/utils/wretch.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import wretch from "wretch";
2-
import { toast } from "./swal";
32

43
export const backend = wretch(process.env.NEXT_PUBLIC_BACKEND_URL!)
54
.options({
65
mode: "cors"
76
})
8-
.catcher(404, () => toast.fire({
9-
title: "Error",
10-
icon: "error",
11-
text: "Resource was not found."
12-
}))
13-
.catcher(500, () => toast.fire({
14-
title: "Error",
15-
icon: "error",
16-
text: "Internal Server Error, try again later."
17-
}));
7+
.catcher(404, async () => {
8+
const { toast } = await import("./swal");
9+
toast.fire({
10+
title: "Error",
11+
icon: "error",
12+
text: "Resource was not found."
13+
});
14+
})
15+
.catcher(500, async () => {
16+
const { toast } = await import("./swal");
17+
18+
toast.fire({
19+
title: "Error",
20+
icon: "error",
21+
text: "Internal Server Error, try again later."
22+
});
23+
});

0 commit comments

Comments
 (0)