From 6612510d2baa31f6bb946b412351b7992b2ffbe1 Mon Sep 17 00:00:00 2001
From: crupest <crupest@outlook.com>
Date: Mon, 5 Jul 2021 22:47:38 +0800
Subject: feat: Fix #623, fix #621.

---
 FrontEnd/src/App.tsx | 100 +++++++++++++++++++++++++--------------------------
 1 file changed, 48 insertions(+), 52 deletions(-)

(limited to 'FrontEnd/src/App.tsx')

diff --git a/FrontEnd/src/App.tsx b/FrontEnd/src/App.tsx
index a4363ff5..6497b071 100644
--- a/FrontEnd/src/App.tsx
+++ b/FrontEnd/src/App.tsx
@@ -13,7 +13,7 @@ import TimelinePage from "./views/timeline";
 import Search from "./views/search";
 import AlertHost from "./views/common/alert/AlertHost";
 
-import { useRawUser } from "./services/user";
+import { useUser } from "./services/user";
 
 const NoMatch: React.FC = () => {
   return <div>Ah-oh, 404!</div>;
@@ -24,60 +24,56 @@ const LazyAdmin = React.lazy(
 );
 
 function App(): ReactElement | null {
-  const user = useRawUser();
+  const user = useUser();
 
-  if (user === undefined) {
-    return <LoadingPage />;
-  } else {
-    return (
-      <React.Suspense fallback={<LoadingPage />}>
-        <Router>
-          <AppBar />
-          <div style={{ height: 56 }} />
-          <Switch>
-            <Route exact path="/">
-              {user == null ? <Home /> : <Center />}
+  return (
+    <React.Suspense fallback={<LoadingPage />}>
+      <Router>
+        <AppBar />
+        <div style={{ height: 56 }} />
+        <Switch>
+          <Route exact path="/">
+            {user == null ? <Home /> : <Center />}
+          </Route>
+          <Route exact path="/home">
+            <Home />
+          </Route>
+          {user != null ? (
+            <Route exact path="/center">
+              <Center />
             </Route>
-            <Route exact path="/home">
-              <Home />
+          ) : null}
+          <Route exact path="/login">
+            <Login />
+          </Route>
+          <Route path="/settings">
+            <Settings />
+          </Route>
+          <Route path="/about">
+            <About />
+          </Route>
+          <Route path="/timelines/:name">
+            <TimelinePage />
+          </Route>
+          <Route path="/users/:username">
+            <User />
+          </Route>
+          <Route path="/search">
+            <Search />
+          </Route>
+          {user && user.hasAdministrationPermission && (
+            <Route path="/admin">
+              <LazyAdmin user={user} />
             </Route>
-            {user != null ? (
-              <Route exact path="/center">
-                <Center />
-              </Route>
-            ) : null}
-            <Route exact path="/login">
-              <Login />
-            </Route>
-            <Route path="/settings">
-              <Settings />
-            </Route>
-            <Route path="/about">
-              <About />
-            </Route>
-            <Route path="/timelines/:name">
-              <TimelinePage />
-            </Route>
-            <Route path="/users/:username">
-              <User />
-            </Route>
-            <Route path="/search">
-              <Search />
-            </Route>
-            {user && user.hasAdministrationPermission && (
-              <Route path="/admin">
-                <LazyAdmin user={user} />
-              </Route>
-            )}
-            <Route>
-              <NoMatch />
-            </Route>
-          </Switch>
-          <AlertHost />
-        </Router>
-      </React.Suspense>
-    );
-  }
+          )}
+          <Route>
+            <NoMatch />
+          </Route>
+        </Switch>
+        <AlertHost />
+      </Router>
+    </React.Suspense>
+  );
 }
 
 export default App;
-- 
cgit v1.2.3

