|
| 1 | +import { |
| 2 | + isRouteErrorResponse, |
| 3 | + Links, |
| 4 | + Meta, |
| 5 | + Outlet, |
| 6 | + Scripts, |
| 7 | + ScrollRestoration, |
| 8 | +} from "react-router"; |
| 9 | + |
| 10 | +import '@mantine/core/styles.css'; |
| 11 | +import { createTheme, MantineProvider } from '@mantine/core'; |
| 12 | + |
| 13 | +import type { Route } from "./+types/root"; |
| 14 | +import "./app.css"; |
| 15 | + |
| 16 | +export const links: Route.LinksFunction = () => [ |
| 17 | + { rel: "preconnect", href: "https://fonts.googleapis.com" }, |
| 18 | + { |
| 19 | + rel: "preconnect", |
| 20 | + href: "https://fonts.gstatic.com", |
| 21 | + crossOrigin: "anonymous", |
| 22 | + }, |
| 23 | + { |
| 24 | + rel: "stylesheet", |
| 25 | + href: "https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap", |
| 26 | + }, |
| 27 | +]; |
| 28 | + |
| 29 | +const theme = createTheme({ |
| 30 | + /** mantine theme overrides */ |
| 31 | +}); |
| 32 | + |
| 33 | +export function Layout({ children }: { children: React.ReactNode }) { |
| 34 | + return ( |
| 35 | + <html lang="en"> |
| 36 | + <head> |
| 37 | + <meta charSet="utf-8" /> |
| 38 | + <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 39 | + <Meta /> |
| 40 | + <Links /> |
| 41 | + </head> |
| 42 | + <body> |
| 43 | + {children} |
| 44 | + <ScrollRestoration /> |
| 45 | + <Scripts /> |
| 46 | + </body> |
| 47 | + </html> |
| 48 | + ); |
| 49 | +} |
| 50 | + |
| 51 | +export default function App() { |
| 52 | + return ( |
| 53 | + <MantineProvider theme={theme}> |
| 54 | + {<Outlet />} |
| 55 | + </MantineProvider> |
| 56 | + ); |
| 57 | +} |
| 58 | + |
| 59 | +export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) { |
| 60 | + let message = "Oops!"; |
| 61 | + let details = "An unexpected error occurred."; |
| 62 | + let stack: string | undefined; |
| 63 | + |
| 64 | + if (isRouteErrorResponse(error)) { |
| 65 | + message = error.status === 404 ? "404" : "Error"; |
| 66 | + details = |
| 67 | + error.status === 404 |
| 68 | + ? "The requested page could not be found." |
| 69 | + : error.statusText || details; |
| 70 | + } else if (import.meta.env.DEV && error && error instanceof Error) { |
| 71 | + details = error.message; |
| 72 | + stack = error.stack; |
| 73 | + } |
| 74 | + |
| 75 | + return ( |
| 76 | + <main className="pt-16 p-4 container mx-auto"> |
| 77 | + <h1>{message}</h1> |
| 78 | + <p>{details}</p> |
| 79 | + {stack && ( |
| 80 | + <pre className="w-full p-4 overflow-x-auto"> |
| 81 | + <code>{stack}</code> |
| 82 | + </pre> |
| 83 | + )} |
| 84 | + </main> |
| 85 | + ); |
| 86 | +} |
0 commit comments