This commit is contained in:
Lim Chee Aun 2024-09-13 20:09:13 +08:00
parent 7ca71efc4c
commit f22bdf568d

View file

@ -329,6 +329,7 @@ function App() {
__BENCHMARK.start('app-init'); __BENCHMARK.start('app-init');
__BENCHMARK.start('time-to-following'); __BENCHMARK.start('time-to-following');
__BENCHMARK.start('time-to-home'); __BENCHMARK.start('time-to-home');
__BENCHMARK.start('time-to-route-root');
useLingui(); useLingui();
useEffect(() => { useEffect(() => {
@ -460,6 +461,17 @@ function App() {
); );
} }
function Root({ isLoggedIn, loading }) {
__BENCHMARK.end('time-to-route-root');
return isLoggedIn ? (
<Home />
) : loading ? (
<Loader id="loader-root" />
) : (
<Welcome />
);
}
function PrimaryRoutes({ isLoggedIn, loading }) { function PrimaryRoutes({ isLoggedIn, loading }) {
const location = useLocation(); const location = useLocation();
const nonRootLocation = useMemo(() => { const nonRootLocation = useMemo(() => {
@ -471,15 +483,7 @@ function PrimaryRoutes({ isLoggedIn, loading }) {
<Routes location={nonRootLocation || location}> <Routes location={nonRootLocation || location}>
<Route <Route
path="/" path="/"
element={ element={<Root isLoggedIn={isLoggedIn} loading={loading} />}
isLoggedIn ? (
<Home />
) : loading ? (
<Loader id="loader-root" />
) : (
<Welcome />
)
}
/> />
<Route path="/login" element={<Login />} /> <Route path="/login" element={<Login />} />
<Route path="/welcome" element={<Welcome />} /> <Route path="/welcome" element={<Welcome />} />