Skip to content

Commit aca07ac

Browse files
committed
refactor: small refactor
1 parent 452e6e2 commit aca07ac

File tree

6 files changed

+74
-59
lines changed

6 files changed

+74
-59
lines changed

src/App.tsx

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,42 @@
11
import { useEffect } from "react";
2-
import { useStore } from "./store/useStore";
2+
import { useStore } from "@/store/useStore";
33

4-
import { getDecodedParam } from "./lib/url";
4+
import { getDecodedParam } from "@/lib/url";
55

6-
import Editor from "./components/editor/editor";
7-
import ButtonsNav from "./components/nav-buttons";
8-
import Stats from "./components/editor/stats";
9-
import Terminal from "./components/editor/terminal";
6+
import Editor from "@/components/editor/editor";
7+
import ButtonsNav from "@/components/nav-buttons";
8+
import Stats from "@/components/editor/stats";
9+
import Terminal from "@/components/editor/terminal";
1010
import {
1111
ResizableHandle,
1212
ResizablePanel,
1313
ResizablePanelGroup
14-
} from "./components/ui/resizable";
14+
} from "@/components/ui/resizable";
1515

16-
function App() {
16+
export default function App() {
1717
const { direction, setCode, initializePyodide, isPyodideLoading } =
1818
useStore();
1919

2020
// Initialize Pyodide and ( set the code from URL params if present )
2121
useEffect(() => {
22-
initializePyodide();
22+
const initializeApp = async () => {
23+
await initializePyodide();
2324

24-
const urlParams = new URLSearchParams(window.location.search);
25-
const encodedParam = urlParams.get("v");
26-
if (encodedParam) {
27-
const decodedCode = getDecodedParam(encodedParam);
28-
if (decodedCode) {
29-
setCode(decodedCode);
25+
const urlParams = new URLSearchParams(window.location.search);
26+
const encodedParam = urlParams.get("v");
27+
if (encodedParam) {
28+
const decodedCode = getDecodedParam(encodedParam);
29+
if (decodedCode) {
30+
setCode(decodedCode);
31+
}
3032
}
31-
}
33+
};
34+
35+
initializeApp();
3236
}, [initializePyodide, setCode]);
3337

3438
if (isPyodideLoading) {
35-
return (
36-
<section className="absolute z-[999] flex h-screen w-full flex-col items-center justify-center gap-3 bg-background text-foreground">
37-
<div className="relative flex h-full w-full flex-col items-center justify-center overflow-hidden bg-background md:shadow-xl">
38-
<img
39-
src="./images/logo.webp"
40-
alt="logo"
41-
className="h-52 w-52 animate-pulse"
42-
/>
43-
<p className="sm:text-1xl mt-2 animate-pulse whitespace-pre-wrap text-center text-xl font-semibold tracking-tighter text-white">
44-
Loading WebAssembly
45-
</p>
46-
</div>
47-
</section>
48-
);
39+
return <LoadingScreen />;
4940
}
5041

5142
return (
@@ -68,4 +59,19 @@ function App() {
6859
);
6960
}
7061

71-
export default App;
62+
function LoadingScreen() {
63+
return (
64+
<section className="absolute z-[999] flex h-screen w-full flex-col items-center justify-center gap-3 bg-background text-foreground">
65+
<div className="relative flex h-full w-full flex-col items-center justify-center overflow-hidden bg-background md:shadow-xl">
66+
<img
67+
src="./images/logo.webp"
68+
alt="logo"
69+
className="h-52 w-52 animate-pulse"
70+
/>
71+
<p className="sm:text-1xl mt-2 animate-pulse whitespace-pre-wrap text-center text-xl font-semibold tracking-tighter text-white">
72+
Loading WebAssembly
73+
</p>
74+
</div>
75+
</section>
76+
);
77+
}

src/components/editor/stats.tsx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface CodeStats {
99
characters: number;
1010
}
1111

12-
const Stats = () => {
12+
export default function Stats() {
1313
const { code } = useStore();
1414

1515
const stats: CodeStats = useMemo(
@@ -42,24 +42,22 @@ const Stats = () => {
4242
</div>
4343
</div>
4444
);
45-
};
45+
}
4646

47-
const StatItem = ({
48-
icon,
49-
value,
50-
label
51-
}: {
47+
interface StatItemProps {
5248
icon: React.ReactNode;
5349
value: number;
5450
label: string;
55-
}) => (
56-
<div className="flex items-center gap-1 space-x-1">
57-
<div className="flex items-center space-x-1">
58-
{icon}
59-
<span className="font-medium">{value}</span>
60-
</div>
61-
<span className="text-xs text-foreground/55">{label}</span>
62-
</div>
63-
);
51+
}
6452

65-
export default Stats;
53+
function StatItem({ icon, value, label }: StatItemProps) {
54+
return (
55+
<div className="flex items-center gap-1 space-x-1">
56+
<div className="flex items-center space-x-1">
57+
{icon}
58+
<span className="font-medium">{value}</span>
59+
</div>
60+
<span className="text-xs text-foreground/55">{label}</span>
61+
</div>
62+
);
63+
}

src/components/editor/terminal.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useEffect, useState, useRef, useCallback, useMemo } from "react";
22
import { useStore } from "@/store/useStore";
3+
34
import Loader from "@/components/loader";
45

56
interface CommandHandlers {
@@ -26,6 +27,7 @@ export default function Terminal() {
2627
}
2728
}, []);
2829

30+
// Scroll to bottom on output change
2931
useEffect(() => {
3032
scrollToBottom();
3133
}, [output, scrollToBottom]);

src/components/loader.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { LoaderCircleIcon } from "lucide-react";
22

3-
export default function Loader({ text }: { text: string }) {
3+
interface LoaderProps {
4+
text: string;
5+
}
6+
7+
export default function Loader({ text }: LoaderProps) {
48
return (
59
<div className="flex items-center gap-1 text-foreground">
610
<LoaderCircleIcon className="h-5 w-5 animate-spin" />

src/components/settings.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ import {
2121
LoaderIcon
2222
} from "lucide-react";
2323

24-
const SettingsSection: React.FC<{
24+
interface SettingsSectionProps {
2525
title: string;
2626
children: React.ReactNode;
27-
}> = ({ title, children }) => (
28-
<div>
29-
<p className="mb-1 text-sm text-muted-foreground">{title}</p>
30-
<div className="flex flex-col gap-1">{children}</div>
31-
</div>
32-
);
27+
}
28+
29+
function SettingsSection({ title, children }: SettingsSectionProps) {
30+
return (
31+
<div>
32+
<p className="mb-1 text-sm text-muted-foreground">{title}</p>
33+
<div className="flex flex-col gap-1">{children}</div>
34+
</div>
35+
);
36+
}
3337

3438
export default function Settings() {
3539
const { code, pipInstall, isLibLoading } = useStore();

src/main.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import "@/globals.css";
2+
13
import React from "react";
24
import ReactDOM from "react-dom/client";
3-
import "./globals.css";
45

5-
import App from "./App.tsx";
6+
import App from "@/App.tsx";
67

7-
ReactDOM.createRoot(document.getElementById("root")!).render(
8+
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
89
<React.StrictMode>
910
<App />
1011
</React.StrictMode>

0 commit comments

Comments
 (0)