-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroot.tsx
210 lines (197 loc) · 4.76 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import {captureRemixErrorBoundaryError, withSentry} from '@sentry/remix';
import {ApolloProvider, gql} from '@apollo/client';
import {
ChakraProvider,
Box,
Heading,
Flex,
Text,
Image,
} from '@chakra-ui/react';
import type {
LinksFunction,
MetaFunction,
LoaderFunctionArgs,
} from '@remix-run/node';
import {
Links,
LiveReload,
Meta,
Outlet,
Scripts,
ScrollRestoration,
isRouteErrorResponse,
useRouteError,
} from '@remix-run/react';
import apolloClient from './utils/apolloClient';
import Header from './components/Header/Header';
import Footer from './components/Footer/Footer';
import theme from './theme';
import photoswipeCSS from 'photoswipe/dist/photoswipe.css?url';
import fontsCSS from '~/styles/fonts.css?url';
import {typedjson} from 'remix-typedjson';
import {RootDocument} from './types/graphql';
import type {RootQuery} from './types/graphql';
import {dateStringComponents} from './components/DateString';
import Headline from './components/Headline';
import {Analytics} from '@vercel/analytics/react';
import {SpeedInsights} from '@vercel/speed-insights/remix';
export const meta: MetaFunction<typeof loader> = (props) => {
let title = 'Kulturspektakel Gauting';
let description =
'Open-Air-Musikfestival mit freiem Eintritt, Workshops, Kinderprogramm und mehr';
const event = props.data?.eventsConnection?.edges[0].node;
if (event) {
const {
date,
connector = '',
to = '',
} = dateStringComponents({
date: new Date(event.start),
to: new Date(event.end),
until: '-',
});
title = `Kulturspektakel Gauting ${date}${connector}${to}`;
description = `Open-Air-Musikfestival vom ${date} bis ${to} mit freiem Eintritt, Workshops, Kinderprogramm und mehr`;
}
return [
{charset: 'utf-8'},
{name: 'viewport', content: 'width=device-width,initial-scale=1'},
{
title,
},
{
name: 'description',
content: description,
},
{
property: 'og:title',
content: title,
},
{
property: 'og:locale',
content: 'de_DE',
},
{
property: 'og:description',
content: description,
},
{
name: 'theme-color',
// TODO
// content: theme.token.offwhite[100],
},
];
};
export const links: LinksFunction = () => [
{
rel: 'stylesheet',
href: fontsCSS,
},
{
rel: 'icon',
type: 'image/png',
href: '/favicon.png',
},
{rel: 'stylesheet', href: photoswipeCSS},
];
gql`
query Root {
eventsConnection(first: 1, type: Kulturspektakel) {
edges {
node {
id
...Header
}
}
}
}
`;
export async function loader(args: LoaderFunctionArgs) {
const {data} = await apolloClient.query<RootQuery>({
query: RootDocument,
});
return typedjson(data);
}
function Document({children}: {children: React.ReactNode}) {
// const emotionCache = createEmotionCache({key: 'css'});
return (
<html lang="de">
<head suppressHydrationWarning>
<Meta />
<Links />
<meta
name="emotion-insertion-point"
content="emotion-insertion-point"
/>
</head>
<body>
<ChakraProvider value={theme}>
<ApolloProvider client={apolloClient}>
<Flex direction={'column'} minHeight={'100vh'}>
<Header />
<Box
flex="1 1 0"
ml="auto"
mr="auto"
maxW="3xl"
p="6"
pb="16"
width="100%"
>
{children}
</Box>
<Footer />
<Analytics />
<SpeedInsights />
</Flex>
</ApolloProvider>
</ChakraProvider>
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}
function App() {
return (
<Document>
<Outlet />
</Document>
);
}
export default withSentry(App);
export function CatchBoundary() {
// when true, this is what used to go to `CatchBoundary`
return (
<Document>
<Box>
<Heading as="h1">Uh oh ...</Heading>
<p>Something went wrong.</p>
</Box>
</Document>
);
}
export function ErrorBoundary() {
const error = useRouteError();
console.error(error);
captureRemixErrorBoundaryError(error);
return (
<Document>
{isRouteErrorResponse(error) && error.status == 404 ? (
<>
<Headline mb="4">Seite nicht gefunden</Headline>
<Image
src="/404.svg"
alt="Trauriger Roboter der die Seite nicht finden konnte"
/>
</>
) : (
<>
<Headline mb="4">Fehler</Headline>
<Text>Da stimmt etwas nicht. Hast du es kaputt gemacht?</Text>
</>
)}
</Document>
);
}