|
7 | 7 | * |
8 | 8 | */ |
9 | 9 |
|
10 | | -import React, { useEffect } from 'react'; |
| 10 | +import React, { useEffect, useState } from 'react'; |
11 | 11 | import { Switch, Route } from 'react-router-dom'; |
12 | 12 | import PropTypes from 'prop-types'; |
13 | | -import { withRouter } from 'react-router'; |
| 13 | +import { Router } from 'react-router'; |
14 | 14 | import map from 'lodash/map'; |
15 | | -import { compose } from 'redux'; |
16 | 15 | import { Layout } from 'antd'; |
| 16 | +import { PersistGate } from 'redux-persist/integration/react'; |
17 | 17 | import { routeConfig } from '@app/routeConfig'; |
18 | 18 | import { ThemeProvider } from 'styled-components'; |
19 | 19 | import GlobalStyle from '@app/global-styles'; |
20 | 20 | import { colors } from '@themes'; |
21 | 21 | import Header from '@components/Header'; |
| 22 | +import ScrollToTop from '@components/ScrollToTop'; |
22 | 23 | import For from '@components/For'; |
23 | 24 | import LanguageProvider from 'containers/LanguageProvider'; |
24 | 25 | import ErrorBoundary from '@app/components/ErrorBoundary/index'; |
25 | 26 | import { translationMessages } from '@app/i18n'; |
| 27 | +import { Provider } from 'react-redux'; |
| 28 | +import history from '@utils/history' |
| 29 | +import configureStore from '@app/configureStore'; |
| 30 | +import If from '@app/components/If/index'; |
26 | 31 |
|
27 | 32 | const theme = { |
28 | 33 | fg: colors.primary, |
29 | 34 | bg: colors.secondary |
30 | 35 | }; |
31 | 36 |
|
32 | | -export function App({ location, history }) { |
| 37 | +export function App({ location }) { |
| 38 | + const [store, setStore] = useState(null); |
| 39 | + const [persistor, setPersistor] = useState(null); |
33 | 40 | useEffect(() => { |
34 | | - if (location.search.includes('?redirect_uri=')) { |
35 | | - const routeToReplace = new URLSearchParams(location.search).get('redirect_uri'); |
36 | | - history.replace(routeToReplace); |
37 | | - } |
| 41 | + // if (location.search.includes('?redirect_uri=')) { |
| 42 | + // const routeToReplace = new URLSearchParams(location.search).get('redirect_uri'); |
| 43 | + // history.replace(routeToReplace); |
| 44 | + // } |
| 45 | + const { store: s, persistor } = configureStore({}, history); |
| 46 | + setStore(s); |
| 47 | + setPersistor(persistor); |
38 | 48 | }, []); |
39 | 49 |
|
40 | 50 | return ( |
41 | | - <ErrorBoundary> |
42 | | - <LanguageProvider messages={translationMessages}> |
43 | | - <ThemeProvider theme={theme}> |
44 | | - <Header /> |
45 | | - <Layout.Content> |
46 | | - <For |
47 | | - ParentComponent={(props) => <Switch {...props} />} |
48 | | - of={map(Object.keys(routeConfig))} |
49 | | - renderItem={(routeKey, index) => { |
50 | | - const Component = routeConfig[routeKey].component; |
51 | | - return ( |
52 | | - <Route |
53 | | - exact={routeConfig[routeKey].exact} |
54 | | - key={index} |
55 | | - path={routeConfig[routeKey].route} |
56 | | - render={(props) => { |
57 | | - const updatedProps = { |
58 | | - ...props, |
59 | | - ...routeConfig[routeKey].props |
60 | | - }; |
61 | | - return <Component {...updatedProps} />; |
62 | | - }} |
63 | | - /> |
64 | | - ); |
65 | | - }} |
66 | | - /> |
67 | | - <GlobalStyle /> |
68 | | - </Layout.Content> |
69 | | - </ThemeProvider> |
70 | | - </LanguageProvider> |
71 | | - </ErrorBoundary> |
| 51 | + <If condition={!!persistor} otherwise={<div>LOADING</div>}> |
| 52 | + <PersistGate loading={null} persistor={persistor}> |
| 53 | + <Router history={history}> |
| 54 | + <ScrollToTop> |
| 55 | + <ErrorBoundary> |
| 56 | + <Provider store={store}> |
| 57 | + <LanguageProvider messages={translationMessages}> |
| 58 | + <ThemeProvider theme={theme}> |
| 59 | + <Header /> |
| 60 | + <Layout.Content> |
| 61 | + <For |
| 62 | + ParentComponent={(props) => <Switch {...props} />} |
| 63 | + of={map(Object.keys(routeConfig))} |
| 64 | + renderItem={(routeKey, index) => { |
| 65 | + const Component = routeConfig[routeKey].component; |
| 66 | + return ( |
| 67 | + <Route |
| 68 | + exact={routeConfig[routeKey].exact} |
| 69 | + key={index} |
| 70 | + path={routeConfig[routeKey].route} |
| 71 | + render={(props) => { |
| 72 | + const updatedProps = { |
| 73 | + ...props, |
| 74 | + ...routeConfig[routeKey].props |
| 75 | + }; |
| 76 | + return <Component {...updatedProps} />; |
| 77 | + }} |
| 78 | + /> |
| 79 | + ); |
| 80 | + }} |
| 81 | + /> |
| 82 | + <GlobalStyle /> |
| 83 | + </Layout.Content> |
| 84 | + </ThemeProvider> |
| 85 | + </LanguageProvider> |
| 86 | + </Provider> |
| 87 | + </ErrorBoundary> |
| 88 | + </ScrollToTop> |
| 89 | + </Router> |
| 90 | + </PersistGate> |
| 91 | + </If> |
72 | 92 | ); |
73 | 93 | } |
74 | 94 | App.propTypes = { |
75 | 95 | location: PropTypes.object, |
76 | 96 | history: PropTypes.object |
77 | 97 | }; |
78 | | -export default compose(withRouter)(App); |
| 98 | +export default App; |
0 commit comments