Test escalate the loading state

This commit is contained in:
Lim Chee Aun 2024-09-16 13:27:58 +08:00
parent 3ebf7af4c3
commit e5d766a076

View file

@ -442,40 +442,36 @@ function App() {
return <HttpRoute />; return <HttpRoute />;
} }
if (uiState === 'loading') {
return <Loader id="loader-root" />;
}
return ( return (
<> <>
<PrimaryRoutes isLoggedIn={isLoggedIn} loading={uiState === 'loading'} /> <PrimaryRoutes isLoggedIn={isLoggedIn} />
<SecondaryRoutes isLoggedIn={isLoggedIn} /> <SecondaryRoutes isLoggedIn={isLoggedIn} />
{uiState === 'default' && ( <Routes>
<Routes> <Route path="/:instance?/s/:id" element={<StatusRoute />} />
<Route path="/:instance?/s/:id" element={<StatusRoute />} /> </Routes>
</Routes>
)}
{isLoggedIn && <ComposeButton />} {isLoggedIn && <ComposeButton />}
{isLoggedIn && <Shortcuts />} {isLoggedIn && <Shortcuts />}
<Modals /> <Modals />
{isLoggedIn && <NotificationService />} {isLoggedIn && <NotificationService />}
<BackgroundService isLoggedIn={isLoggedIn} /> <BackgroundService isLoggedIn={isLoggedIn} />
{uiState !== 'loading' && <SearchCommand onClose={focusDeck} />} <SearchCommand onClose={focusDeck} />
<KeyboardShortcutsHelp /> <KeyboardShortcutsHelp />
</> </>
); );
} }
function Root({ isLoggedIn, loading }) { function Root({ isLoggedIn }) {
if (isLoggedIn) { if (isLoggedIn) {
__BENCHMARK.end('time-to-isLoggedIn'); __BENCHMARK.end('time-to-isLoggedIn');
} }
return isLoggedIn ? ( return isLoggedIn ? <Home /> : <Welcome />;
<Home />
) : loading ? (
<Loader id="loader-root" />
) : (
<Welcome />
);
} }
const PrimaryRoutes = memo(({ isLoggedIn, loading }) => { const PrimaryRoutes = memo(({ isLoggedIn }) => {
const location = useLocation(); const location = useLocation();
const nonRootLocation = useMemo(() => { const nonRootLocation = useMemo(() => {
const { pathname } = location; const { pathname } = location;
@ -484,10 +480,7 @@ const PrimaryRoutes = memo(({ isLoggedIn, loading }) => {
return ( return (
<Routes location={nonRootLocation || location}> <Routes location={nonRootLocation || location}>
<Route <Route path="/" element={<Root isLoggedIn={isLoggedIn} />} />
path="/"
element={<Root isLoggedIn={isLoggedIn} loading={loading} />}
/>
<Route path="/login" element={<Login />} /> <Route path="/login" element={<Login />} />
<Route path="/welcome" element={<Welcome />} /> <Route path="/welcome" element={<Welcome />} />
</Routes> </Routes>