forked from nasa-gcn/gcn.nasa.gov
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot.tsx
197 lines (183 loc) · 4.95 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
/*!
* Copyright © 2022 United States Government as represented by the Administrator
* of the National Aeronautics and Space Administration. No copyright is claimed
* in the United States under Title 17, U.S. Code. All Other Rights Reserved.
*
* SPDX-License-Identifier: NASA-1.3
*
*
* +-------------+
* | TACH! TACH! |
* +-------------+
* \\ /
* \\ (o> /
* (o> //\
* ____(()_____V_/_____
* || ||
* ||
*
*
*/
import {
Link,
Links,
LiveReload,
Meta,
Outlet,
Scripts,
ScrollRestoration,
useCatch,
useMatches,
useTransition,
} from '@remix-run/react'
import type {
MetaFunction,
LinksFunction,
DataFunctionArgs,
} from '@remix-run/node'
import { ButtonGroup, GovBanner, GridContainer } from '@trussworks/react-uswds'
import { Footer } from './components/Footer'
import { Header } from './components/Header'
import highlightStyle from 'highlight.js/styles/github.css'
import TopBarProgress from 'react-topbar-progress-indicator'
import { DevBanner } from './components/DevBanner'
import { useSpinDelay } from 'spin-delay'
import { getUser } from './routes/__auth/user.server'
TopBarProgress.config({
barColors: {
'0': '#e52207',
'0.5': '#ffffff',
'1.0': '#0050d8',
},
})
export const handle = {
breadcrumb: 'GCN',
}
export const meta: MetaFunction = () => {
return {
charset: 'utf-8',
viewport: 'width=device-width,initial-scale=1',
}
}
export const links: LinksFunction = () => [
{
rel: 'stylesheet',
href: '/_static/theme/css/custom.css',
},
{
rel: 'stylesheet',
href: highlightStyle,
},
...[16, 40, 57, 72, 114, 144, 192].map((size) => ({
rel: 'icon',
href: `/_static/theme/img/favicons/favicon-${size}.png`,
sizes: `${size}x${size}`,
})),
]
export async function loader({ request }: DataFunctionArgs) {
const { url } = request
const user = await getUser(request)
const email = user?.email
return { url, email }
}
export function useUrl() {
const [{ data }] = useMatches()
const { url } = data as Awaited<ReturnType<typeof loader>>
return url
}
export function useHostname() {
return new URL(useUrl()).hostname
}
function Document({ children }: { children?: React.ReactNode }) {
const matches = useMatches()
const [{ data }] = matches
const { email } = data as Awaited<ReturnType<typeof loader>>
const transition = useTransition()
const showProgress = useSpinDelay(transition.state !== 'idle')
const breadcrumbs = matches
.map(({ handle }) => handle?.breadcrumb)
.filter(Boolean)
const title = breadcrumbs.join(' - ')
return (
<html lang="en-US">
<head>
<Meta />
<Links />
<title>{title}</title>
</head>
<body>
<a className="usa-skipnav" href="#main-content">
Skip to main content
</a>
{showProgress && <TopBarProgress />}
<GovBanner />
<DevBanner />
<Header email={email} />
<div className="bg-gold padding-x-2 desktop:padding-x-4 padding-y-1 line-height-sans-3 font-lang-4">
<GridContainer>
<span className="text-bold">
GECAM Notices are here! Receive them via Kafka or email.
</span>{' '}
See{' '}
<Link to="/news" className="hover:text-no-underline">
news and announcements
</Link>
</GridContainer>
</div>
<section className="usa-section main-content">
<GridContainer>{children}</GridContainer>
</section>
<Footer />
<ScrollRestoration />
<Scripts />
<LiveReload />
</body>
</html>
)
}
export function CatchBoundary() {
const { status } = useCatch()
const [{ data }] = useMatches()
if (status == 403) {
const { url } = data as Awaited<ReturnType<typeof loader>>
return (
<Document>
<h1>Unauthorized</h1>
<p className="usa-intro">
We're sorry, you must log in to access the page you're looking for.
</p>
<p>Log in to access that page, or go home.</p>
<ButtonGroup>
<Link
to={`/login?redirect=${encodeURIComponent(url)}`}
className="usa-button"
>
Log in and take me there
</Link>
<Link to="/" className="usa-button usa-button--outline">
Go home
</Link>
</ButtonGroup>
</Document>
)
} else {
return (
<Document>
<h1>Unexpected error (HTTP {status})</h1>
<p className="usa-intro">An unexpected error occurred.</p>
<ButtonGroup>
<Link to="/" className="usa-button">
Go home
</Link>
</ButtonGroup>
</Document>
)
}
}
export default function App() {
return (
<Document>
<Outlet />
</Document>
)
}