refactor: rebuild root with toaster, model-viewer script and error screen
This commit is contained in:
parent
812c97157f
commit
c6266d3fb7
83
app/root.tsx
83
app/root.tsx
@ -1,46 +1,38 @@
|
|||||||
import {
|
import type { ReactNode } from 'react';
|
||||||
isRouteErrorResponse,
|
import { isRouteErrorResponse, Links, Meta, Outlet, Scripts, ScrollRestoration } from 'react-router';
|
||||||
Links,
|
import { AlertTriangle } from 'lucide-react';
|
||||||
Meta,
|
import { Toaster } from 'sonner';
|
||||||
Outlet,
|
import type { Route } from './+types/root';
|
||||||
Scripts,
|
import { Button } from '~/components/ui/button';
|
||||||
ScrollRestoration,
|
import { StatusScreen } from '~/components/ui/status-screen';
|
||||||
} from "react-router";
|
import { MODEL_VIEWER_SCRIPT_URL } from '~/data/brand';
|
||||||
|
import './app.css';
|
||||||
import type { Route } from "./+types/root";
|
|
||||||
import "./app.css";
|
|
||||||
|
|
||||||
export const links: Route.LinksFunction = () => [
|
export const links: Route.LinksFunction = () => [
|
||||||
{ rel: "icon", href: "/favicon.svg", type: "image/svg+xml" },
|
{ rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
|
||||||
{ rel: "preconnect", href: "https://fonts.googleapis.com" },
|
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
|
||||||
|
{ rel: 'preconnect', href: 'https://fonts.gstatic.com', crossOrigin: 'anonymous' },
|
||||||
{
|
{
|
||||||
rel: "preconnect",
|
rel: 'stylesheet',
|
||||||
href: "https://fonts.gstatic.com",
|
href: 'https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap',
|
||||||
crossOrigin: "anonymous",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rel: "stylesheet",
|
|
||||||
href: "https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap",
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
import { Toaster } from "sonner";
|
export function Layout({ children }: { children: ReactNode }) {
|
||||||
|
|
||||||
export function Layout({ children }: { children: React.ReactNode }) {
|
|
||||||
return (
|
return (
|
||||||
<html lang="en">
|
<html lang='en'>
|
||||||
<head>
|
<head>
|
||||||
<meta charSet="utf-8" />
|
<meta charSet='utf-8' />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name='viewport' content='width=device-width, initial-scale=1, viewport-fit=cover' />
|
||||||
<Meta />
|
<Meta />
|
||||||
<Links />
|
<Links />
|
||||||
<script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/4.0.0/model-viewer.min.js"></script>
|
<script type='module' src={MODEL_VIEWER_SCRIPT_URL}></script>
|
||||||
</head>
|
</head>
|
||||||
<body className="bg-[#0D0D0D] text-white">
|
<body className='bg-background font-sans text-text-primary antialiased'>
|
||||||
{children}
|
{children}
|
||||||
<ScrollRestoration />
|
<ScrollRestoration />
|
||||||
<Scripts />
|
<Scripts />
|
||||||
<Toaster theme="dark" position="bottom-right" richColors />
|
<Toaster theme='dark' position='bottom-right' richColors />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
@ -51,30 +43,17 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
|
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
|
||||||
let message = "Oops!";
|
const notFound = isRouteErrorResponse(error) && error.status === 404;
|
||||||
let details = "An unexpected error occurred.";
|
const stack = import.meta.env.DEV && error instanceof Error ? error.stack : undefined;
|
||||||
let stack: string | undefined;
|
|
||||||
|
|
||||||
if (isRouteErrorResponse(error)) {
|
|
||||||
message = error.status === 404 ? "404" : "Error";
|
|
||||||
details =
|
|
||||||
error.status === 404
|
|
||||||
? "The requested page could not be found."
|
|
||||||
: error.statusText || details;
|
|
||||||
} else if (import.meta.env.DEV && error && error instanceof Error) {
|
|
||||||
details = error.message;
|
|
||||||
stack = error.stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="pt-16 p-4 container mx-auto">
|
<StatusScreen
|
||||||
<h1>{message}</h1>
|
icon={AlertTriangle}
|
||||||
<p>{details}</p>
|
title={notFound ? 'Page not found' : 'Something went wrong'}
|
||||||
{stack && (
|
message={notFound ? 'The page you are looking for does not exist.' : 'Please try again in a moment.'}
|
||||||
<pre className="w-full p-4 overflow-x-auto">
|
action={<Button onClick={() => window.location.reload()}>Try again</Button>}
|
||||||
<code>{stack}</code>
|
>
|
||||||
</pre>
|
{stack && <pre className='mt-6 max-h-64 overflow-auto rounded-card-sm bg-surface p-4 text-left font-mono text-xs text-text-muted'>{stack}</pre>}
|
||||||
)}
|
</StatusScreen>
|
||||||
</main>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user