Skip to content

Commit 95abe3c

Browse files
committed
feat: 调整项目结构
1 parent 5d50fd3 commit 95abe3c

File tree

3 files changed

+81
-87
lines changed

3 files changed

+81
-87
lines changed

frontend/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
</head>
2121

2222
<body>
23-
<script type="module" src="/src/Main.tsx"></script>
23+
<script type="module" src="/src/App.tsx"></script>
2424
</body>
2525
</html>

frontend/src/App.tsx

Lines changed: 80 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,95 @@
1-
import { LoadingPage } from "@sscreator/ui";
1+
import { LoadingPage, useColorScheme } from "@sscreator/ui";
2+
import "@unocss/reset/tailwind.css";
23
import type { VNode } from "preact";
3-
import { Suspense, lazy } from "preact/compat";
4+
import { StrictMode, Suspense, lazy, render } from "preact/compat";
5+
import { ErrorBoundary } from "react-error-boundary";
6+
import { Toaster } from "react-hot-toast";
7+
import { install } from "resize-observer";
8+
import "uno.css";
9+
import { registerSW } from "virtual:pwa-register";
410
import type { RouteProps } from "wouter-preact";
511
import { Route, Switch } from "wouter-preact";
12+
import ErrorFallback from "./components/ErrorFallback";
13+
import Footer from "./components/Footer";
614
import ToolWrapper from "./components/ToolWrapper";
715
import MainPage from "./pages/MainPage";
816
import ThanksPage from "./pages/ThanksPage";
917
import V2UnavaliablePage from "./pages/V2UnavaliablePage";
1018
import V2UnimplementedPage from "./pages/V2UnimplementedPage";
1119
import { routes } from "./routes";
1220

21+
import "@sscreator/ui/dist/sscreator-ui.css";
22+
23+
// 处理 Safari 浏览器上的 ResizeObserver 兼容性问题
24+
if (!window.ResizeObserver) {
25+
install();
26+
}
27+
28+
// 注册 PWA
29+
registerSW({ immediate: true });
30+
1331
const NotFoundPage = lazy(() => import("./pages/NotFoundPage"));
1432

15-
export default function App() {
33+
export default function Main() {
34+
const { colorScheme } = useColorScheme();
35+
1636
return (
17-
<Switch>
18-
<Route path="/">
19-
<MainPage />
20-
</Route>
21-
{
22-
routes.map((item) => (
23-
<Route key={item.path} path={item.path}>
24-
<ToolWrapper toolName={item.toolName} Component={item.component} />
25-
</Route>
26-
)) as unknown as VNode<RouteProps<undefined, string>>
27-
}
28-
<Route path="/thanks">
29-
<Suspense fallback={<LoadingPage />}>
30-
<ThanksPage />
31-
</Suspense>
32-
</Route>
33-
<Route path="/v2-unimplemented">
34-
<Suspense fallback={<LoadingPage />}>
35-
<V2UnimplementedPage />
36-
</Suspense>
37-
</Route>
38-
<Route path="/v2-unavaliable">
39-
<Suspense fallback={<LoadingPage />}>
40-
<V2UnavaliablePage />
41-
</Suspense>
42-
</Route>
43-
<Route>
44-
<Suspense fallback={<LoadingPage />}>
45-
<NotFoundPage />
46-
</Suspense>
47-
</Route>
48-
</Switch>
37+
<StrictMode>
38+
<ErrorBoundary FallbackComponent={ErrorFallback}>
39+
<div className="mx-auto my-7 max-w-4xl min-h-screen w-[90vw]">
40+
<Switch>
41+
<Route path="/">
42+
<MainPage />
43+
</Route>
44+
{
45+
routes.map((item) => (
46+
<Route key={item.path} path={item.path}>
47+
<ToolWrapper
48+
toolName={item.toolName}
49+
Component={item.component}
50+
/>
51+
</Route>
52+
)) as unknown as VNode<RouteProps<undefined, string>>
53+
}
54+
<Route path="/thanks">
55+
<Suspense fallback={<LoadingPage />}>
56+
<ThanksPage />
57+
</Suspense>
58+
</Route>
59+
<Route path="/v2-unimplemented">
60+
<Suspense fallback={<LoadingPage />}>
61+
<V2UnimplementedPage />
62+
</Suspense>
63+
</Route>
64+
<Route path="/v2-unavaliable">
65+
<Suspense fallback={<LoadingPage />}>
66+
<V2UnavaliablePage />
67+
</Suspense>
68+
</Route>
69+
<Route>
70+
<Suspense fallback={<LoadingPage />}>
71+
<NotFoundPage />
72+
</Suspense>
73+
</Route>
74+
</Switch>
75+
</div>
76+
<Footer />
77+
</ErrorBoundary>
78+
79+
<Toaster
80+
toastOptions={{
81+
style: {
82+
background: colorScheme === "dark" ? "#3f3f46" : undefined,
83+
color: colorScheme === "dark" ? "#f4f4f5" : undefined,
84+
},
85+
86+
blank: {
87+
duration: 2000,
88+
},
89+
}}
90+
/>
91+
</StrictMode>
4992
);
5093
}
94+
95+
render(<Main />, document.body);

frontend/src/Main.tsx

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)