|
1
|
import { Switch, Route } from "wouter"; |
|
2
|
import { queryClient } from "./lib/queryClient"; |
|
3
|
import { QueryClientProvider } from "@tanstack/react-query"; |
|
4
|
import { Toaster } from "@/components/ui/toaster"; |
|
5
|
import { TooltipProvider } from "@/components/ui/tooltip"; |
|
6
|
import { ThemeProvider } from "@/contexts/theme-context"; |
|
7
|
import { useAuth } from "@/hooks/useAuth"; |
|
8
|
import { lazy, Suspense } from "react"; |
|
9
|
import MainLayout from "@/components/layout/main-layout"; |
|
10
|
|
|
11
|
// Core pages loaded immediately |
|
12
|
import Home from "@/pages/home"; |
|
13
|
import Landing from "@/pages/landing"; |
|
14
|
import AuthPage from "@/pages/auth"; |
|
15
|
|
|
16
|
// Lazy load secondary pages |
|
17
|
const Favorites = lazy(() => import("@/pages/favorites")); |
|
18
|
const RepairGuide = lazy(() => import("@/pages/repair-guide")); |
|
19
|
const Troubleshooting = lazy(() => import("@/pages/troubleshooting")); |
|
20
|
const SoftwareTools = lazy(() => import("@/pages/software-tools")); |
|
21
|
const DeviceFinder = lazy(() => import("@/pages/device-finder")); |
|
22
|
const CreateGuide = lazy(() => import("@/pages/create-guide")); |
|
23
|
const OfflineSettings = lazy(() => import("@/pages/offline-settings")); |
|
24
|
const Downloads = lazy(() => import("@/pages/downloads")); |
|
25
|
const AdminDashboard = lazy(() => import("@/pages/admin-dashboard")); |
|
26
|
const NotFound = lazy(() => import("@/pages/not-found")); |
|
27
|
|
|
28
|
import { PageLoadingSpinner } from "@/components/ui/loading-spinner"; |
|
29
|
import { useHashLocation } from "@/hooks/use-hash-location"; |
|
30
|
import { Router as WouterRouter } from "wouter"; |
|
31
|
|
|
32
|
function Router() { |
|
33
|
const { user, isLoading, isAuthenticated } = useAuth(); |
|
34
|
|
|
35
|
if (isLoading) { |
|
36
|
return <PageLoadingSpinner />; |
|
37
|
} |
|
38
|
|
|
39
|
return ( |
|
40
|
<WouterRouter hook={useHashLocation}> |
|
41
|
{!isAuthenticated ? ( |
|
42
|
<Switch> |
|
43
|
<Route path="/" component={Landing} /> |
|
44
|
<Route path="/auth" component={AuthPage} /> |
|
45
|
<Route component={NotFound} /> |
|
46
|
</Switch> |
|
47
|
) : ( |
|
48
|
<MainLayout> |
|
49
|
<Suspense fallback={<PageLoadingSpinner />}> |
|
50
|
<Switch> |
|
51
|
<Route path="/" component={Home} /> |
|
52
|
<Route path="/favorites" component={Favorites} /> |
|
53
|
<Route path="/guide/:id" component={RepairGuide} /> |
|
54
|
<Route path="/troubleshooting/:type?" component={Troubleshooting} /> |
|
55
|
<Route path="/software-tools" component={SoftwareTools} /> |
|
56
|
<Route path="/device-finder" component={DeviceFinder} /> |
|
57
|
<Route path="/create-guide" component={CreateGuide} /> |
|
58
|
<Route path="/offline-settings" component={OfflineSettings} /> |
|
59
|
<Route path="/downloads" component={Downloads} /> |
|
60
|
<Route path="/admin" component={AdminDashboard} /> |
|
61
|
<Route component={NotFound} /> |
|
62
|
</Switch> |
|
63
|
</Suspense> |
|
64
|
</MainLayout> |
|
65
|
)} |
|
66
|
</WouterRouter> |
|
67
|
); |
|
68
|
} |
|
69
|
|
|
70
|
function App() { |
|
71
|
return ( |
|
72
|
<ThemeProvider defaultTheme="dark" storageKey="jcr-guide-theme"> |
|
73
|
<QueryClientProvider client={queryClient}> |
|
74
|
<TooltipProvider> |
|
75
|
<Toaster /> |
|
76
|
<Router /> |
|
77
|
</TooltipProvider> |
|
78
|
</QueryClientProvider> |
|
79
|
</ThemeProvider> |
|
80
|
); |
|
81
|
} |
|
82
|
|
|
83
|
export default App; |