feat: implement lazy loading for LoginPage and add Suspense to IntranetLayout

This commit is contained in:
Thibault Pouch
2026-02-27 10:22:37 +01:00
parent 992b4340bd
commit 4607e79b8b
2 changed files with 45 additions and 30 deletions

View File

@@ -20,12 +20,18 @@ const IntranetModeration = lazy(() => import('./pages/intranet/IntranetModerat
export default function App() { export default function App() {
return ( return (
<AuthProvider> <AuthProvider>
<Suspense fallback={<PageLoader />}>
<Routes> <Routes>
{/* Login */} {/* Login — own Suspense so the full-page loader only shows here */}
<Route path="/login" element={<LoginPage />} /> <Route
path="/login"
element={
<Suspense fallback={<PageLoader />}>
<LoginPage />
</Suspense>
}
/>
{/* Intranet (staff only) */} {/* Intranet (staff only) — Suspense is inside IntranetLayout */}
<Route <Route
path="/intranet" path="/intranet"
element={ element={
@@ -48,7 +54,6 @@ export default function App() {
{/* Catch-all: redirect to intranet */} {/* Catch-all: redirect to intranet */}
<Route path="*" element={<Navigate to="/intranet" replace />} /> <Route path="*" element={<Navigate to="/intranet" replace />} />
</Routes> </Routes>
</Suspense>
</AuthProvider> </AuthProvider>
); );
} }

View File

@@ -1,6 +1,6 @@
import { NavLink, Outlet, useNavigate } from 'react-router-dom'; import { NavLink, Outlet, useNavigate } from 'react-router-dom';
import { useAuth } from '../../contexts/AuthContext'; import { useAuth } from '../../contexts/AuthContext';
import { useCallback } from 'react'; import { useCallback, Suspense } from 'react';
const INTRANET_LINKS = [ const INTRANET_LINKS = [
{ to: '/intranet', label: 'Dashboard', icon: '[>]', end: true }, { to: '/intranet', label: 'Dashboard', icon: '[>]', end: true },
@@ -21,7 +21,7 @@ export function IntranetLayout() {
}, [logout, navigate]); }, [logout, navigate]);
return ( return (
<div style={{ display: 'flex', minHeight: '100vh', background: 'var(--color-bg)' }}> <div style={{ display: 'flex', height: '100vh', overflow: 'hidden', background: 'var(--color-bg)' }}>
{/* Sidebar */} {/* Sidebar */}
<aside <aside
style={{ style={{
@@ -141,9 +141,19 @@ export function IntranetLayout() {
</div> </div>
</aside> </aside>
{/* Main content */} {/* Main content — only this area scrolls */}
<main style={{ flex: 1, overflowY: 'auto', padding: '2rem', background: 'var(--color-bg)' }}> <main style={{ flex: 1, overflowY: 'auto', padding: '2rem', background: 'var(--color-bg)' }}>
<Suspense
fallback={
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%' }}>
<div style={{ fontFamily: 'var(--font-mono)', color: 'var(--color-text-muted)', fontSize: '0.8rem', letterSpacing: '0.1em' }}>
LOADING...
</div>
</div>
}
>
<Outlet /> <Outlet />
</Suspense>
</main> </main>
</div> </div>
); );