From 5813ca780f4c0b7f77e0601e4b2b299cda343af5 Mon Sep 17 00:00:00 2001
From: CaIon <1808837298@qq.com>
Date: Tue, 8 Apr 2025 17:31:46 +0800
Subject: [PATCH] feat: Integrate SetupCheck component for improved setup
validation in routing
---
web/src/App.js | 5 +++--
web/src/components/SetupCheck.js | 18 ++++++++++++++++++
web/src/pages/Home/index.js | 7 ++-----
3 files changed, 23 insertions(+), 7 deletions(-)
create mode 100644 web/src/components/SetupCheck.js
diff --git a/web/src/App.js b/web/src/App.js
index 15f449be..4f6ddc83 100644
--- a/web/src/App.js
+++ b/web/src/App.js
@@ -26,6 +26,7 @@ import Playground from './pages/Playground/Playground.js';
import OAuth2Callback from "./components/OAuth2Callback.js";
import PersonalSetting from './components/PersonalSetting.js';
import Setup from './pages/Setup/index.js';
+import SetupCheck from './components/SetupCheck';
const Home = lazy(() => import('./pages/Home'));
const Detail = lazy(() => import('./pages/Detail'));
@@ -35,7 +36,7 @@ function App() {
const location = useLocation();
return (
- <>
+
} />
- >
+
);
}
diff --git a/web/src/components/SetupCheck.js b/web/src/components/SetupCheck.js
new file mode 100644
index 00000000..99364b00
--- /dev/null
+++ b/web/src/components/SetupCheck.js
@@ -0,0 +1,18 @@
+import React, { useContext, useEffect } from 'react';
+import { Navigate, useLocation } from 'react-router-dom';
+import { StatusContext } from '../context/Status';
+
+const SetupCheck = ({ children }) => {
+ const [statusState] = useContext(StatusContext);
+ const location = useLocation();
+
+ useEffect(() => {
+ if (statusState?.status?.setup === false && location.pathname !== '/setup') {
+ window.location.href = '/setup';
+ }
+ }, [statusState?.status?.setup, location.pathname]);
+
+ return children;
+};
+
+export default SetupCheck;
\ No newline at end of file
diff --git a/web/src/pages/Home/index.js b/web/src/pages/Home/index.js
index d6a2de71..57e396b1 100644
--- a/web/src/pages/Home/index.js
+++ b/web/src/pages/Home/index.js
@@ -66,13 +66,9 @@ const Home = () => {
};
useEffect(() => {
- if (statusState.status?.setup === false) {
- window.location.href = '/setup';
- return;
- }
displayNotice().then();
displayHomePageContent().then();
- });
+ }, []);
return (
<>
@@ -116,6 +112,7 @@ const Home = () => {
https://github.com/Calcium-Ion/new-api
+
{t('协议')}: