|
| 1 | +import { |
| 2 | + isRouteErrorResponse, |
| 3 | + Links, |
| 4 | + Meta, |
| 5 | + Outlet, |
| 6 | + Scripts, |
| 7 | + ScrollRestoration, |
| 8 | + useLocation, |
| 9 | +} from "react-router"; |
| 10 | + |
| 11 | +import "@mantine/core/styles.css"; |
| 12 | +import { |
| 13 | + createTheme, |
| 14 | + MantineProvider, |
| 15 | + Container, |
| 16 | + Button, |
| 17 | + Input, |
| 18 | + Card, |
| 19 | +} from "@mantine/core"; |
| 20 | + |
| 21 | +import type { Route } from "./+types/root"; |
| 22 | +import "./app.css"; |
| 23 | +import Header from "./components/header/header"; |
| 24 | + |
| 25 | +export const links: Route.LinksFunction = () => [ |
| 26 | + { rel: "preconnect", href: "https://fonts.googleapis.com" }, |
| 27 | + { |
| 28 | + rel: "preconnect", |
| 29 | + href: "https://fonts.gstatic.com", |
| 30 | + crossOrigin: "anonymous", |
| 31 | + }, |
| 32 | + { |
| 33 | + rel: "stylesheet", |
| 34 | + href: "https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap", |
| 35 | + }, |
| 36 | +]; |
| 37 | + |
| 38 | +const theme = createTheme({ |
| 39 | + /** mantine theme overrides */ |
| 40 | + colors: { |
| 41 | + "brand-yellow": [ |
| 42 | + "#fff9df", |
| 43 | + "#fff2ca", |
| 44 | + "#ffe399", |
| 45 | + "#ffd463", |
| 46 | + "#ffc736", |
| 47 | + "#ffc01e", |
| 48 | + "#ffba02", |
| 49 | + "#e4a300", |
| 50 | + "#cb9100", |
| 51 | + "#af7c00", |
| 52 | + ], |
| 53 | + "custom-gray": [ |
| 54 | + "#f5f5f4", |
| 55 | + "#e7e7e7", |
| 56 | + "#cdcdcd", |
| 57 | + "#b2b2b2", |
| 58 | + "#9a9a9a", |
| 59 | + "#8b8b8b", |
| 60 | + "#848484", |
| 61 | + "#717171", |
| 62 | + "#646464", |
| 63 | + "#343231", |
| 64 | + ], |
| 65 | + green: [ |
| 66 | + "#e5ffe5", |
| 67 | + "#cefecf", |
| 68 | + "#9ffa9f", |
| 69 | + "#6bf76b", |
| 70 | + "#48f548", |
| 71 | + "#24f324", |
| 72 | + "#0df212", |
| 73 | + "#00d701", |
| 74 | + "#00c000", |
| 75 | + "#00a600", |
| 76 | + ], |
| 77 | + |
| 78 | + yellow: [ |
| 79 | + "#fff9df", |
| 80 | + "#fff2ca", |
| 81 | + "#ffe399", |
| 82 | + "#ffd463", |
| 83 | + "#ffc736", |
| 84 | + "#ffc01e", |
| 85 | + "#ffba02", |
| 86 | + "#e4a300", |
| 87 | + "#cb9100", |
| 88 | + "#af7c00", |
| 89 | + ], |
| 90 | + |
| 91 | + red: [ |
| 92 | + "#ffe7e8", |
| 93 | + "#ffcece", |
| 94 | + "#ff9b9b", |
| 95 | + "#ff6464", |
| 96 | + "#fe3736", |
| 97 | + "#fe1b19", |
| 98 | + "#ff0000", |
| 99 | + "#e40000", |
| 100 | + "#cb0000", |
| 101 | + "#b20000", |
| 102 | + ], |
| 103 | + }, |
| 104 | + |
| 105 | + components: { |
| 106 | + Button: Button.extend({ |
| 107 | + defaultProps: { |
| 108 | + variant: "filled", |
| 109 | + color: "brand-yellow", |
| 110 | + c: "custom-gray.9", |
| 111 | + }, |
| 112 | + }), |
| 113 | + |
| 114 | + Input: Input.extend({}), |
| 115 | + |
| 116 | + InputWrapper: Input.Wrapper.extend({ |
| 117 | + classNames: { |
| 118 | + label: "text-white", |
| 119 | + error: "text-red-500", |
| 120 | + }, |
| 121 | + }), |
| 122 | + }, |
| 123 | + |
| 124 | + primaryColor: "brand-yellow", |
| 125 | + primaryShade: { light: 6, dark: 6 }, |
| 126 | +}); |
| 127 | + |
| 128 | +export function Layout({ children }: { children: React.ReactNode }) { |
| 129 | + return ( |
| 130 | + <html lang="en"> |
| 131 | + <head> |
| 132 | + <meta charSet="utf-8" /> |
| 133 | + <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 134 | + <Meta /> |
| 135 | + <Links /> |
| 136 | + </head> |
| 137 | + <body> |
| 138 | + {children} |
| 139 | + <ScrollRestoration /> |
| 140 | + <Scripts /> |
| 141 | + </body> |
| 142 | + </html> |
| 143 | + ); |
| 144 | +} |
| 145 | + |
| 146 | +export default function App() { |
| 147 | + const location = useLocation(); |
| 148 | + const linksWithHeader = ["/user"]; |
| 149 | + |
| 150 | + const isHeader = () => { |
| 151 | + return linksWithHeader.includes(location.pathname); |
| 152 | + }; |
| 153 | + |
| 154 | + return ( |
| 155 | + <MantineProvider theme={theme} defaultColorScheme="dark"> |
| 156 | + {isHeader() && <Header />} |
| 157 | + <Container fluid>{<Outlet />}</Container> |
| 158 | + </MantineProvider> |
| 159 | + ); |
| 160 | +} |
| 161 | + |
| 162 | +export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) { |
| 163 | + let message = "Oops!"; |
| 164 | + let details = "An unexpected error occurred."; |
| 165 | + let stack: string | undefined; |
| 166 | + |
| 167 | + if (isRouteErrorResponse(error)) { |
| 168 | + message = error.status === 404 ? "404" : "Error"; |
| 169 | + details = |
| 170 | + error.status === 404 |
| 171 | + ? "The requested page could not be found." |
| 172 | + : error.statusText || details; |
| 173 | + } else if (import.meta.env.DEV && error && error instanceof Error) { |
| 174 | + details = error.message; |
| 175 | + stack = error.stack; |
| 176 | + } |
| 177 | + |
| 178 | + return ( |
| 179 | + <main className="pt-16 p-4 container mx-auto"> |
| 180 | + <h1>{message}</h1> |
| 181 | + <p>{details}</p> |
| 182 | + {stack && ( |
| 183 | + <pre className="w-full p-4 overflow-x-auto"> |
| 184 | + <code>{stack}</code> |
| 185 | + </pre> |
| 186 | + )} |
| 187 | + </main> |
| 188 | + ); |
| 189 | +} |
0 commit comments