-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path_app.js
79 lines (69 loc) · 2.11 KB
/
_app.js
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
import Head from "next/head";
import { useEffect, useReducer } from "react";
import { ThemeProvider } from "styled-components";
import { config } from "@fortawesome/fontawesome-svg-core";
import "@fortawesome/fontawesome-svg-core/styles.css";
import Layout from "../components/layout";
import GlobalStyle from "../lib/global-style";
import { ThemeContext } from "../lib/theme";
import { authReducer, initialAuthState } from "../lib/ducks/auth";
import useTheme from "../lib/hooks/useTheme";
import StateContext from "../lib/state";
import { makeApiRequest } from "../lib/api";
config.autoAddCss = false;
function App({ Component, pageProps }) {
const themeHook = useTheme();
const [theme] = themeHook;
const [userState, dispatch] = useReducer(authReducer, initialAuthState);
const props = {
...pageProps,
dispatch,
};
useEffect(() => {
if (!userState.outdated) return;
makeApiRequest("/identity/@me")
.then((res) => res.json().then((data) => ({ data, ok: res.ok })))
.then(({ data, ok }) => {
if (ok) {
dispatch({ type: "restore", user: data });
} else {
throw new Error(data.error);
}
})
.catch(() => {
// Ignore for now. Flash warning in future?
});
}, [userState.outdated]);
return (
<ThemeProvider theme={theme}>
<Head>
<title>The Snakeroom</title>
<meta
name="description"
content="The Snakeroom is an organization dedicated to solving and
discussing Reddit's yearly April Fools events and official
Reddit-run ARGs — both before and while they happen."
/>
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content={theme.colors.background} />
<link
rel="apple-touch-icon"
href="/icons/apple-touch-icon.png"
/>
<link rel="manifest" href="/manifest.json" />
</Head>
<GlobalStyle />
<ThemeContext.Provider value={themeHook}>
<StateContext.Provider value={userState}>
<Layout>
<Component {...props} />
</Layout>
</StateContext.Provider>
</ThemeContext.Provider>
</ThemeProvider>
);
}
export default App;