generated from edmundhung/remix-cloudflare-template
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathroot.tsx
117 lines (105 loc) · 2.37 KB
/
root.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import type {
LinksFunction,
MetaFunction,
LoaderArgs,
} from '@remix-run/cloudflare';
import { json } from '@remix-run/cloudflare';
import type { ShouldReloadFunction } from '@remix-run/react';
import {
Meta,
Links,
Scripts,
LiveReload,
useCatch,
Outlet,
} from '@remix-run/react';
import stylesUrl from '~/styles/tailwind.css';
export let links: LinksFunction = () => {
return [
{ rel: 'stylesheet', href: stylesUrl },
{ rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
];
};
export let meta: MetaFunction = () => {
return {
'color-scheme': 'dark',
viewport: 'width=device-width, initial-scale=1',
};
};
export async function loader({ context }: LoaderArgs) {
const { session } = context;
const [data, setCookieHeader] = await session.getData();
return json(data, {
headers: {
'Set-Cookie': setCookieHeader,
},
});
}
export const unstable_shouldReload: ShouldReloadFunction = ({ submission }) => {
return submission?.formData.get('type') !== 'view';
};
function Document({
children,
title,
}: {
children: React.ReactNode;
title?: string;
}) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
{title ? <title>{title}</title> : null}
<Meta />
<Links />
<script
defer
data-domain="remix.guide"
src="https://plausible.io/js/script.js"
/>
</head>
<body className="relative w-full min-h-screen flex bg-gray-900 text-gray-200">
{children}
<Scripts />
{process.env.NODE_ENV === 'development' ? <LiveReload /> : null}
</body>
</html>
);
}
export default function App() {
return (
<Document>
<Outlet />
</Document>
);
}
export function CatchBoundary() {
let caught = useCatch();
switch (caught.status) {
case 401:
case 404:
return (
<Document title={`${caught.status} ${caught.statusText}`}>
<div className="min-h-screen py-4 flex flex-1 flex-col justify-center items-center">
<h1>
{caught.status} {caught.statusText}
</h1>
</div>
</Document>
);
default:
throw new Error(
`Unexpected caught response with status: ${caught.status}`,
);
}
}
export function ErrorBoundary({ error }: { error: Error }) {
console.error(error);
return (
<Document title="Uh-oh!">
<div className="min-h-screen py-4 flex flex-1 flex-col justify-center items-center">
<h1>Sorry, something went wrong...</h1>
</div>
</Document>
);
}