Skip to content

Commit 6a3d7b3

Browse files
added loading component for editor loading
1 parent 54b79b7 commit 6a3d7b3

File tree

7 files changed

+43
-3
lines changed

7 files changed

+43
-3
lines changed

app/components/code-capture/code-image-preview.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@
33
import useStore from "@/lib/store/store";
44
import WindowContent from "./preview/window-content";
55
import WindowHeader from "./preview/window-header";
6+
import { cn } from "@/lib/utils";
7+
import CodeImageLoadingSkelton from "./preview/code-image-loading-skelton";
68

79
export default function CodeImagePreview() {
810
const windowWidth = useStore((state) => state.windowWidth);
11+
const isEditorMounted = useStore((state) => state.isEditorMounted);
912

1013
return (
1114
<div className="preview items-center py-3 px-4 flex flex-col w-full rounded-md bg-[#191919]">
1215
<div className="preview-box w-full mt-40">
1316
{/* frame */}
1417
<div
15-
className="frame mx-auto max-w-full bg-gradient-to-tr to-purple-600 from-blue-400 rounded-md px-4 py-4"
18+
className={cn(
19+
"frame mx-auto max-w-full bg-gradient-to-tr to-purple-600 from-blue-400 rounded-md px-8 py-8",
20+
!isEditorMounted && "hidden"
21+
)}
1622
style={{
17-
width: windowWidth + 32,
23+
width: windowWidth + 8 * 4 * 2,
1824
}}
1925
>
2026
<div
@@ -28,6 +34,8 @@ export default function CodeImagePreview() {
2834
<WindowContent />
2935
</div>
3036
</div>
37+
38+
{!isEditorMounted && <CodeImageLoadingSkelton />}
3139
</div>
3240
</div>
3341
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default function CodeImageLoadingSkelton() {
2+
return (
3+
<div
4+
className="frame mx-auto max-w-full rounded-md px-4 py-4"
5+
style={{
6+
width: 400 + 32,
7+
}}
8+
>
9+
<div
10+
className="window flex flex-col border rounded-md border-[#82738E] min-h-40"
11+
style={{
12+
width: 400,
13+
}}
14+
></div>
15+
</div>
16+
);
17+
}

lib/monoco-editor.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default function MonacoEditor() {
1414
const changeWindowWidth = useStore((state) => state.changeWindowWidth);
1515

1616
const editorTheme = useStore((state) => state.editorTheme);
17+
const changeEditorMounted = useStore((state) => state.changeEditorMounted);
1718

1819
const editorLanguage = useStore((state) => state.editorLanguage);
1920

@@ -40,6 +41,7 @@ export default function MonacoEditor() {
4041
}`}
4142
theme="vs-dark"
4243
onMount={(editor) => {
44+
changeEditorMounted(true);
4345
editorRef.current = editor;
4446
updateEditorWindowTheme(editorTheme);
4547
}}

lib/store/slices/code-image-slice.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import CodeImageSlice from "@/lib/types/store/slices/code-image-slice";
2+
import { SetState } from "@/lib/types/store/store";
3+
4+
export default function createCodeImageSlice(set: SetState): CodeImageSlice {
5+
return {};
6+
}

lib/store/slices/editor-slice.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import EditorSlice from "@/lib/types/store/slices/editor-slice";
22
import { SetState } from "@/lib/types/store/store";
33

4-
export default function createEditorSlice(set : SetState): EditorSlice {
4+
export default function createEditorSlice(set: SetState): EditorSlice {
55
return {
66
editorTheme: "Night Owl",
77
changeEditorTheme: (theme) =>
@@ -22,5 +22,8 @@ export default function createEditorSlice(set : SetState): EditorSlice {
2222
set(() => ({
2323
editorThemeColors: themeColors,
2424
})),
25+
26+
isEditorMounted: false,
27+
changeEditorMounted: (value) => set(() => ({ isEditorMounted: value })),
2528
};
2629
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default interface CodeImageSlice {}

lib/types/store/slices/editor-slice.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ export default interface EditorSlice {
1111

1212
editorThemeColors: EditorThemeColors;
1313
changeEditorThemeColors: (themeColors: EditorThemeColors) => void;
14+
15+
isEditorMounted : boolean,
16+
changeEditorMounted : (value : boolean) => void,
1417
}

0 commit comments

Comments
 (0)