import { lazy, Suspense, useId } from 'react'; import { Routes, Route, Navigate, useLocation } from 'react-router-dom'; import { useAuth } from '@/hooks/useAuth'; import Layout from '@/components/layout/Layout'; import AppNavigation from '@/components/layout/Sidebar'; import { ReleaseNotesDialog } from '@/components/ReleaseNotesDialog'; import LoginPage from '@/pages/LoginPage'; import ErrorBoundary from '@/components/ErrorBoundary'; import PageLoader from '@/components/PageLoader'; // TanStack Query import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; const queryClient = new QueryClient({ defaultOptions: { queries: { staleTime: 1000 * 60 * 2, // 2 minutes retry: 1, refetchOnWindowFocus: false, }, }, }); // Lazy-loaded components const AdminPage = lazy(() => import('@/pages/AdminPage')); const TrackerPage = lazy(() => import('@/pages/TrackerPage')); const CalendarPage = lazy(() => import('@/pages/CalendarPage')); const SummaryPage = lazy(() => import('@/pages/SummaryPage')); const BillsPage = lazy(() => import('@/pages/BillsPage')); const CategoriesPage = lazy(() => import('@/pages/CategoriesPage')); const SettingsPage = lazy(() => import('@/pages/SettingsPage')); const StatusPage = lazy(() => import('@/pages/StatusPage')); const AnalyticsPage = lazy(() => import('@/pages/AnalyticsPage')); const ReleaseNotesPage = lazy(() => import('@/pages/ReleaseNotesPage')); const AboutPage = lazy(() => import('@/pages/AboutPage')); const RoadmapPage = lazy(() => import('@/pages/RoadmapPage')); const DataPage = lazy(() => import('@/pages/DataPage')); const ProfilePage = lazy(() => import('@/pages/ProfilePage')); const SnowballPage = lazy(() => import('@/pages/SnowballPage')); function RequireAuth({ children, role }) { const { user, singleUserMode } = useAuth(); const location = useLocation(); // Loading state if (user === undefined) { return (
Loading...
); } // Single-user mode bypass if (singleUserMode && role === 'user') return children; // Not authenticated if (!user) { return ; } const roleAllowed = !role || user.role === role || (role === 'user' && user.role === 'admin'); if (role === 'user' && user.is_default_admin) { return ; } // Role mismatch if (!roleAllowed) { return ; } return children; } function AdminShell({ children }) { return (
{children}
); } export default function App() { const { user } = useAuth(); const mainContentId = useId(); return ( {/* Release notes (only for user role) */} {user?.role === 'user' && } {/* Skip link for keyboard users */} Skip to main content
} /> }>} /> }>} /> }> } /> }> } /> }> } /> }> } /> } /> } > }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> } />
); }