-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_app.tsx
80 lines (67 loc) · 2.28 KB
/
_app.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
import 'react-multi-carousel/lib/styles.css';
import { Container, Fade, LinearProgress, makeStyles } from '@material-ui/core';
import CssBaseline from '@material-ui/core/CssBaseline';
import { ThemeProvider } from '@material-ui/core/styles';
import Head from 'next/head';
import { useRouter } from 'next/router';
import React, { useEffect, useState } from 'react';
import AppBar from '../components/navigation/AppBar';
import theme from '../styles/theme';
interface Props {
Component: React.ElementType;
pageProps: object;
}
const useStyles = makeStyles({
progressBar: {
position: 'fixed',
width: '100%',
bottom: 0,
left: 0
}
});
export default function App(props: Props) {
const classes = useStyles();
const router = useRouter();
const { Component, pageProps } = props;
const [loading, setLoading] = useState(false);
useEffect(() => {
// Remove the server-side injected CSS.
const jssStyles = document.querySelector('#jss-server-side');
if (jssStyles) {
jssStyles.parentElement.removeChild(jssStyles);
}
// Add listeners for detecting route changes
const handleRouteStart = () => setLoading(true);
const handleRouteEnd = () => setLoading(false);
router.events.on('routeChangeStart', handleRouteStart);
router.events.on('routeChangeComplete', handleRouteEnd);
router.events.on('routeChangeError', handleRouteEnd);
// Unmount events
return () => {
router.events.off('routeChangeStart', handleRouteStart);
router.events.off('routeChangeComplete', handleRouteEnd);
router.events.off('routeChangeError', handleRouteEnd);
};
}, []);
return (
<>
<Head>
<title>Wookie Movies</title>
<meta content="minimum-scale=1, initial-scale=1, width=device-width" name="viewport" />
</Head>
<ThemeProvider theme={theme}>
<CssBaseline />
<AppBar />
<Container maxWidth="lg" style={{ paddingTop: 20 }}>
<Component {...pageProps} />
</Container>
<Fade
in={loading} mountOnEnter
unmountOnExit
>
<LinearProgress className={classes.progressBar} color="secondary" />
</Fade>
</ThemeProvider>
</>
);
}