|
1 | | -import { useEffect, useMemo, useState } from "react" |
| 1 | +import { lazy, Suspense, useEffect, useMemo, useState } from "react" |
2 | 2 | import { HashRouter, Route, Routes, Navigate } from "react-router-dom" |
3 | 3 | import { AppLayout } from "@/app/Layout" |
4 | | -import { LauncherPage } from "@/app/pages/LauncherPage" |
5 | | -import { SearchPage } from "@/app/pages/SearchPage" |
6 | | -import { GameDetailPage } from "@/app/pages/GameDetailPage" |
7 | | -import { LibraryPage } from "@/app/pages/LibraryPage" |
8 | | -import { CollectionsPage } from "@/app/pages/CollectionsPage" |
9 | | -import { DownloadsPage } from "@/app/pages/DownloadsPage" |
10 | | -import { SettingsPage } from "@/app/pages/SettingsPage" |
11 | | -import { WishlistPage } from "@/app/pages/WishlistPage" |
12 | | -import { LikedPage } from "@/app/pages/LikedPage" |
13 | | -import { AccountOverviewPage } from "@/app/pages/AccountOverviewPage" |
14 | | -import { ViewHistoryPage } from "@/app/pages/ViewHistoryPage" |
15 | | -import { SearchHistoryPage } from "@/app/pages/SearchHistoryPage" |
16 | | -import { ScreenshotsPage } from "@/app/pages/ScreenshotsPage" |
17 | | -import { LoginPage } from "@/app/pages/LoginPage" |
18 | | -import { VerifyEmailPage } from "@/app/pages/VerifyEmailPage" |
19 | | -import { ForgotPasswordPage } from "@/app/pages/ForgotPasswordPage" |
20 | | -import { ResetPasswordPage } from "@/app/pages/ResetPasswordPage" |
21 | 4 | import { DownloadsProvider, useDownloads } from "@/context/downloads-context" |
22 | 5 | import { ToastProvider } from "@/context/toast-context" |
23 | 6 | import { AuthProvider } from "@/context/auth-context" |
24 | | -import { InGameOverlay } from "@/components/InGameOverlay" |
25 | 7 | import { Toaster } from "@/components/Toaster" |
26 | 8 | import { Button } from "@/components/ui/button" |
27 | 9 | import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog" |
28 | 10 | import { AlertTriangle } from "lucide-react" |
29 | 11 |
|
| 12 | +const LauncherPage = lazy(() => import("@/app/pages/LauncherPage").then((m) => ({ default: m.LauncherPage }))) |
| 13 | +const SearchPage = lazy(() => import("@/app/pages/SearchPage").then((m) => ({ default: m.SearchPage }))) |
| 14 | +const GameDetailPage = lazy(() => import("@/app/pages/GameDetailPage").then((m) => ({ default: m.GameDetailPage }))) |
| 15 | +const LibraryPage = lazy(() => import("@/app/pages/LibraryPage").then((m) => ({ default: m.LibraryPage }))) |
| 16 | +const CollectionsPage = lazy(() => import("@/app/pages/CollectionsPage").then((m) => ({ default: m.CollectionsPage }))) |
| 17 | +const DownloadsPage = lazy(() => import("@/app/pages/DownloadsPage").then((m) => ({ default: m.DownloadsPage }))) |
| 18 | +const SettingsPage = lazy(() => import("@/app/pages/SettingsPage").then((m) => ({ default: m.SettingsPage }))) |
| 19 | +const WishlistPage = lazy(() => import("@/app/pages/WishlistPage").then((m) => ({ default: m.WishlistPage }))) |
| 20 | +const LikedPage = lazy(() => import("@/app/pages/LikedPage").then((m) => ({ default: m.LikedPage }))) |
| 21 | +const AccountOverviewPage = lazy(() => import("@/app/pages/AccountOverviewPage").then((m) => ({ default: m.AccountOverviewPage }))) |
| 22 | +const ViewHistoryPage = lazy(() => import("@/app/pages/ViewHistoryPage").then((m) => ({ default: m.ViewHistoryPage }))) |
| 23 | +const SearchHistoryPage = lazy(() => import("@/app/pages/SearchHistoryPage").then((m) => ({ default: m.SearchHistoryPage }))) |
| 24 | +const ScreenshotsPage = lazy(() => import("@/app/pages/ScreenshotsPage").then((m) => ({ default: m.ScreenshotsPage }))) |
| 25 | +const LoginPage = lazy(() => import("@/app/pages/LoginPage").then((m) => ({ default: m.LoginPage }))) |
| 26 | +const VerifyEmailPage = lazy(() => import("@/app/pages/VerifyEmailPage").then((m) => ({ default: m.VerifyEmailPage }))) |
| 27 | +const ForgotPasswordPage = lazy(() => import("@/app/pages/ForgotPasswordPage").then((m) => ({ default: m.ForgotPasswordPage }))) |
| 28 | +const ResetPasswordPage = lazy(() => import("@/app/pages/ResetPasswordPage").then((m) => ({ default: m.ResetPasswordPage }))) |
| 29 | +const InGameOverlay = lazy(() => import("@/components/InGameOverlay").then((m) => ({ default: m.InGameOverlay }))) |
| 30 | + |
| 31 | +function RouteFallback() { |
| 32 | + return <div className="min-h-screen bg-[#09090b]" /> |
| 33 | +} |
| 34 | + |
30 | 35 | function ExtractionCloseGuard() { |
31 | 36 | const { downloads } = useDownloads() |
32 | 37 | const [request, setRequest] = useState<{ mode: "quit" | "hide"; extractionCount?: number; downloadCount?: number; appids?: string[] } | null>(null) |
@@ -104,36 +109,38 @@ export default function App() { |
104 | 109 | <ToastProvider> |
105 | 110 | <AuthProvider> |
106 | 111 | <DownloadsProvider> |
107 | | - <Routes> |
108 | | - <Route path="/overlay" element={<InGameOverlay />} /> |
| 112 | + <Suspense fallback={<RouteFallback />}> |
| 113 | + <Routes> |
| 114 | + <Route path="/overlay" element={<InGameOverlay />} /> |
109 | 115 |
|
110 | | - {/* Auth pages (inside app layout) */} |
111 | | - <Route path="/login" element={<LoginPage />} /> |
112 | | - <Route path="/verify-email" element={<VerifyEmailPage />} /> |
113 | | - <Route path="/forgot-password" element={<ForgotPasswordPage />} /> |
114 | | - <Route path="/reset-password" element={<ResetPasswordPage />} /> |
| 116 | + {/* Auth pages (inside app layout) */} |
| 117 | + <Route path="/login" element={<LoginPage />} /> |
| 118 | + <Route path="/verify-email" element={<VerifyEmailPage />} /> |
| 119 | + <Route path="/forgot-password" element={<ForgotPasswordPage />} /> |
| 120 | + <Route path="/reset-password" element={<ResetPasswordPage />} /> |
115 | 121 |
|
116 | | - {/* App routes - no login required */} |
117 | | - <Route element={<AppWithDownloads />}> |
118 | | - <Route path="/" element={<LauncherPage />} /> |
119 | | - <Route path="/launcher" element={<LauncherPage />} /> |
120 | | - <Route path="/search" element={<SearchPage />} /> |
121 | | - <Route path="/game/:id" element={<GameDetailPage />} /> |
122 | | - <Route path="/library" element={<LibraryPage />} /> |
123 | | - <Route path="/collections" element={<CollectionsPage />} /> |
124 | | - <Route path="/downloads" element={<DownloadsPage />} /> |
125 | | - <Route path="/settings" element={<SettingsPage />} /> |
126 | | - <Route path="/wishlist" element={<WishlistPage />} /> |
127 | | - <Route path="/liked" element={<LikedPage />} /> |
128 | | - <Route path="/account" element={<AccountOverviewPage />} /> |
129 | | - <Route path="/view-history" element={<ViewHistoryPage />} /> |
130 | | - <Route path="/search-history" element={<SearchHistoryPage />} /> |
131 | | - <Route path="/screenshots" element={<ScreenshotsPage />} /> |
132 | | - </Route> |
| 122 | + {/* App routes - no login required */} |
| 123 | + <Route element={<AppWithDownloads />}> |
| 124 | + <Route path="/" element={<LauncherPage />} /> |
| 125 | + <Route path="/launcher" element={<LauncherPage />} /> |
| 126 | + <Route path="/search" element={<SearchPage />} /> |
| 127 | + <Route path="/game/:id" element={<GameDetailPage />} /> |
| 128 | + <Route path="/library" element={<LibraryPage />} /> |
| 129 | + <Route path="/collections" element={<CollectionsPage />} /> |
| 130 | + <Route path="/downloads" element={<DownloadsPage />} /> |
| 131 | + <Route path="/settings" element={<SettingsPage />} /> |
| 132 | + <Route path="/wishlist" element={<WishlistPage />} /> |
| 133 | + <Route path="/liked" element={<LikedPage />} /> |
| 134 | + <Route path="/account" element={<AccountOverviewPage />} /> |
| 135 | + <Route path="/view-history" element={<ViewHistoryPage />} /> |
| 136 | + <Route path="/search-history" element={<SearchHistoryPage />} /> |
| 137 | + <Route path="/screenshots" element={<ScreenshotsPage />} /> |
| 138 | + </Route> |
133 | 139 |
|
134 | | - {/* Fallback */} |
135 | | - <Route path="*" element={<Navigate to="/" replace />} /> |
136 | | - </Routes> |
| 140 | + {/* Fallback */} |
| 141 | + <Route path="*" element={<Navigate to="/" replace />} /> |
| 142 | + </Routes> |
| 143 | + </Suspense> |
137 | 144 | </DownloadsProvider> |
138 | 145 | </AuthProvider> |
139 | 146 | <Toaster /> |
|
0 commit comments