60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
import type { ReactNode } from 'react';
|
|
import { isRouteErrorResponse, Links, Meta, Outlet, Scripts, ScrollRestoration } from 'react-router';
|
|
import { AlertTriangle } from 'lucide-react';
|
|
import { Toaster } from 'sonner';
|
|
import type { Route } from './+types/root';
|
|
import { Button } from '~/components/ui/button';
|
|
import { StatusScreen } from '~/components/ui/status-screen';
|
|
import { MODEL_VIEWER_SCRIPT_URL } from '~/data/brand';
|
|
import './app.css';
|
|
|
|
export const links: Route.LinksFunction = () => [
|
|
{ rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
|
|
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
|
|
{ rel: 'preconnect', href: 'https://fonts.gstatic.com', crossOrigin: 'anonymous' },
|
|
{
|
|
rel: 'stylesheet',
|
|
href: 'https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap',
|
|
},
|
|
];
|
|
|
|
export function Layout({ children }: { children: ReactNode }) {
|
|
return (
|
|
<html lang='en'>
|
|
<head>
|
|
<meta charSet='utf-8' />
|
|
<meta name='viewport' content='width=device-width, initial-scale=1, viewport-fit=cover' />
|
|
<Meta />
|
|
<Links />
|
|
<script type='module' src={MODEL_VIEWER_SCRIPT_URL}></script>
|
|
</head>
|
|
<body className='bg-background font-sans text-text-primary antialiased'>
|
|
{children}
|
|
<ScrollRestoration />
|
|
<Scripts />
|
|
<Toaster theme='dark' position='bottom-right' richColors />
|
|
</body>
|
|
</html>
|
|
);
|
|
}
|
|
|
|
export default function App() {
|
|
return <Outlet />;
|
|
}
|
|
|
|
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
|
|
const notFound = isRouteErrorResponse(error) && error.status === 404;
|
|
const stack = import.meta.env.DEV && error instanceof Error ? error.stack : undefined;
|
|
|
|
return (
|
|
<StatusScreen
|
|
icon={AlertTriangle}
|
|
title={notFound ? 'Page not found' : 'Something went wrong'}
|
|
message={notFound ? 'The page you are looking for does not exist.' : 'Please try again in a moment.'}
|
|
action={<Button onClick={() => window.location.reload()}>Try again</Button>}
|
|
>
|
|
{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>
|
|
);
|
|
}
|