-
Notifications
You must be signed in to change notification settings - Fork 20
/
App.tsx
58 lines (53 loc) · 2.14 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
import { ConnectedRouter } from 'connected-react-router';
import { History } from 'history';
import * as React from 'react';
import { Route, Switch } from 'react-router-dom';
import { Flex } from 'rebass';
import { useAuth0 } from '../auth/Auth0Wrapper';
import PrivateRoute from '../auth/PrivateRoute';
import AppFooter from '../shared-components/AppFooter';
import FullscreenLoader from '../shared-components/FullscreenLoader';
import GaTracker from '../shared-components/GaTracker';
import HomePage from '../shared-components/HomePage';
import Navbar from '../shared-components/Navbar';
import ScrollToTop from '../shared-components/ScrollToTop';
// tslint:disable-next-line:space-in-parens
const BooksPage = React.lazy(() => import(/* webpackChunkName: "books" */'../books/BooksPage'));
// tslint:disable-next-line:space-in-parens
const NotFoundPage = React.lazy(() => import(/* webpackChunkName: "not-found" */'../shared-components/NotFoundPage'));
interface AppProps {
history: History;
}
const App = ({
history,
}: AppProps) => {
const { isLoggingIn, loginWithRedirect, logout, user } = useAuth0();
return (
<ConnectedRouter history={history}>
<GaTracker>
<ScrollToTop>
{
isLoggingIn ?
<FullscreenLoader style={{ height: '100%' }} delay={0} /> :
<Flex flexDirection="column" style={{ height: '100%' }}>
<Navbar
user={user}
handleLogin={() => loginWithRedirect({ appState: { targetUrl: '/books' } })}
handleLogout={() => logout({ returnTo: window.location.origin, client_id: process.env.AUTH0_CLIENT_ID })}
/>
<React.Suspense fallback={<FullscreenLoader />}>
<Switch>
<Route path="/" exact component={HomePage} />
<PrivateRoute path="/books" component={BooksPage} />
<Route component={NotFoundPage} />
</Switch>
</React.Suspense>
<AppFooter />
</Flex>
}
</ScrollToTop>
</GaTracker>
</ConnectedRouter>
);
};
export default App;