-
-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathApp.tsx
More file actions
162 lines (149 loc) · 4.88 KB
/
App.tsx
File metadata and controls
162 lines (149 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { useEffect, useState } from "react";
import { App as AntdApp, Layout, Spin } from "antd";
import { LoadingOutlined } from "@ant-design/icons";
import { Routes, Route, useSearchParams, useNavigate } from "react-router-dom";
import Navbar from "./components/Navbar";
import tour from "./components/Tour";
import LearnNow from "./pages/LearnNow";
import useAppStore from "./store/store";
import { shallow } from "zustand/shallow";
import LearnContent from "./components/Content";
import MainContainer from "./pages/MainContainer";
import PlaygroundSidebar from "./components/PlaygroundSidebar";
import "./styles/App.css";
import AIConfigPopup from "./components/AIConfigPopup";
const { Content } = Layout;
const App = () => {
const navigate = useNavigate();
const init = useAppStore((state) => state.init);
const loadFromLink = useAppStore((state) => state.loadFromLink);
const { isAIConfigOpen, setAIConfigOpen } = useAppStore(
(state) => ({
isAIConfigOpen: state.isAIConfigOpen,
setAIConfigOpen: state.setAIConfigOpen,
}),
shallow
);
const backgroundColor = useAppStore((state) => state.backgroundColor);
const textColor = useAppStore((state) => state.textColor);
const [loading, setLoading] = useState(true);
const [searchParams] = useSearchParams();
useEffect(() => {
const initializeApp = async () => {
try {
setLoading(true);
let compressedData: string | null = null;
if (window.location.hash.startsWith("#data=")) {
compressedData = window.location.hash.substring(6);
} else {
compressedData = searchParams.get("data");
}
if (compressedData) {
await loadFromLink(compressedData);
if (window.location.pathname !== "/") {
navigate("/", { replace: true });
}
} else {
await init();
}
} catch (error) {
console.error("Initialization error:", error);
} finally {
setLoading(false);
}
};
void initializeApp();
}, [init, loadFromLink, searchParams, navigate]);
useEffect(() => {
const style = document.createElement("style");
style.innerHTML = `
.ant-collapse-header {
color: ${textColor} !important;
}
.ant-collapse-content {
background-color: ${backgroundColor} !important;
}
.ant-collapse-content-active {
background-color: ${backgroundColor} !important;
}
`;
document.head.appendChild(style);
return () => {
document.head.removeChild(style);
};
}, [backgroundColor, textColor]);
useEffect(() => {
const startTour = async () => {
try {
await tour.start();
localStorage.setItem("hasVisited", "true");
} catch (error) {
console.error("Tour failed to start:", error);
}
};
const showTour = searchParams.get("showTour") === "true";
if (showTour || !localStorage.getItem("hasVisited")) {
void startTour();
}
}, [searchParams]);
useEffect(() => {
const theme = backgroundColor === "#121212" ? "dark" : "light";
document.documentElement.setAttribute("data-theme", theme);
}, [backgroundColor]);
return (
<AntdApp>
<Layout style={{ height: "100vh" }}>
<Navbar />
<Layout
className="app-layout"
style={{
backgroundColor,
height: "calc(100vh - 64px)",
marginTop: "64px",
overflow: "hidden",
}}
>
<Routes>
<Route
path="/"
element={
<>
<PlaygroundSidebar />
<Content style={{ marginLeft: "64px" }}>
{loading ? (
<div className="app-content-loading">
<Spinner />
</div>
) : (
<div className="app-main-content">
<MainContainer />
</div>
)}
</Content>
<AIConfigPopup
isOpen={isAIConfigOpen}
onClose={() => setAIConfigOpen(false)}
/>
</>
}
/>
<Route path="/learn" element={<LearnNow />}>
<Route path="intro" element={<LearnContent file="intro.md" />} />
<Route path="module1" element={<LearnContent file="module1.md" />} />
<Route path="module2" element={<LearnContent file="module2.md" />} />
<Route path="module3" element={<LearnContent file="module3.md" />} />
</Route>
</Routes>
</Layout>
</Layout>
</AntdApp>
);
};
const Spinner = () => (
<div className="app-spinner-container">
<Spin
indicator={<LoadingOutlined style={{ fontSize: 42, color: "#19c6c7" }} spin />}
/>
</div>
);
export default App;