import {
ChakraProvider,
Container,
cookieStorageManagerSSR,
Heading,
Link,
Text,
} from "@chakra-ui/react";
import { ClientStyleContext, ServerStyleContext } from "./context.js";
import fontStyle from "@fontsource-variable/plus-jakarta-sans/index.css";
import Forbidden from "../components/Forbidden.js";
import globalStyles from "../index.css";
import {
isRouteErrorResponse,
Links,
Meta,
Outlet,
Scripts,
useLoaderData,
useRouteError,
useRouteLoaderData,
} from "@remix-run/react";
import { type ErrorResponse } from "@remix-run/router";
import { LinksFunction } from "@remix-run/cloudflare";
import Login from "../components/Login.js";
import Navigation from "../components/Navigation.js";
import { type ReactNode, StrictMode, useContext, useEffect } from "react";
import theme from "../theme.js";
import { withEmotionCache } from "@emotion/react";
import {
captureRemixErrorBoundaryError,
setUser,
withSentry,
} from "@sentry/remix";
export function ErrorBoundary() {
const error = useRouteError() as ErrorResponse;
if (!isRouteErrorResponse(error))
return (
???
Something bad happened!
Details: {error}
location.reload()}>
Refresh
);
const { status } = error;
const loaderData = useRouteLoaderData("root") || {};
switch (status) {
case 303:
return "";
case 401:
return (
);
case 403:
return (
);
case 404:
return (
404
There is nothing to find here.
history.go(-1)}>
Go back
);
default:
captureRemixErrorBoundaryError(useRouteError());
return (
500
S̶̡͈̠̗̠͖͙̭o̶̶͕͚̥͍̪̤m̸̨͏͈͔̖͚̖̰̱͞e҉̵͖͚͇̀t̕͟͠͏͎̺̯̲̱̣̤̠̟͙̠̙̫̬ḩ̸̭͓̬͎̙̀į̞̮͉͖̰̥̹͚̫̙̪̗̜̳̕ͅn҉͔̯̪̗̝̝͖̲͇͍͎̲̲̤̖̫͈̪͡g̴̰̻̙̝͉̭͇̖̰̝̙͕̼͙͘͜ ̵̶̫̥̳̲̘̻̗͈͕̭̲͇̘̜̺̟̥̖̥b̴̙̭̹͕̞͠r̞͎̠̩͈̖̰̞̯̯͢͢͠ͅo̝̯̗̹̳͍̰͉͕̘̰̠̺̥̰͔̕ͅk̵̸̻̠͕̺̦̦͖̲̺̦̞̝̞͞͡e̶͏̤̼̼͔̘̰̰̭͈̀͞͡
location.reload()}>
Reload
);
}
}
export const links: LinksFunction = () => {
return [
{ href: "/favicon.ico", rel: "icon" },
{ href: "/files/logo192.png", rel: "apple-touch-icon", type: "image/png" },
{ href: fontStyle, rel: "stylesheet" },
{ href: globalStyles, rel: "stylesheet" },
];
};
export async function loader({
context,
}: {
context: RequestContext;
}): Promise<{ [k: string]: any }> {
let data: { [k: string]: string } = {};
if (context.env.COMMIT_SHA) data.commit_sha = context.env.COMMIT_SHA;
if (context.data.current_user) data = { ...context.data.current_user };
if (context.env.REMIX_DSN) data.dsn = context.env.REMIX_DSN;
if (context.data.nonce) data.nonce = context.data.nonce;
if (context.data.theme) data.theme = context.data.theme;
return data;
}
export function meta() {
return [{ title: "Car Crushers" }];
}
function DocumentWrapper(props: {
loaderData: { [k: string]: any };
children: ReactNode;
}) {
const { children: child, loaderData } = props;
const Document = withEmotionCache(
({ children }: { children: ReactNode }, emotionCache) => {
const serverStyleData = useContext(ServerStyleContext);
const clientStyleData = useContext(ClientStyleContext);
useEffect(() => {
emotionCache.sheet.container = document.head;
const tags = emotionCache.sheet.tags;
emotionCache.sheet.flush();
tags.forEach((tag) => {
(emotionCache.sheet as any)._insertTag(tag);
});
clientStyleData?.reset();
}, []);
const body = (
{children}
);
return (
{serverStyleData?.map(({ key, ids, css }) => (
))}
{loaderData.commit_sha ? (
) : null}
{loaderData.dsn ? (
) : null}
{body}
);
},
);
return {child};
}
function App() {
const loaderData = useLoaderData();
if (
loaderData.id &&
[0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].find(
(p) => loaderData.permissions & (1 << p),
)
)
setUser({
email: loaderData.email,
id: loaderData.id,
username: loaderData.username,
});
return (
);
}
export default withSentry(App);