2019-01-03 17:14:25 +03:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { Provider } from 'react-redux';
|
2020-10-26 02:32:04 +03:00
|
|
|
import { Store } from 'redux';
|
2021-08-31 01:18:02 +03:00
|
|
|
import { Persistor } from 'redux-persist';
|
|
|
|
import { PersistGate } from 'redux-persist/integration/react';
|
2019-01-03 17:14:25 +03:00
|
|
|
import configureStore from './store/configureStore';
|
|
|
|
import { CONNECT_REQUEST } from './constants/socketActionTypes';
|
|
|
|
import App from './containers/App';
|
2020-10-26 02:32:04 +03:00
|
|
|
import { StoreState } from './reducers';
|
2021-08-31 01:18:02 +03:00
|
|
|
import { StoreAction } from './actions';
|
2020-10-26 02:32:04 +03:00
|
|
|
|
2021-08-31 01:18:02 +03:00
|
|
|
class Root extends Component {
|
2020-10-26 02:32:04 +03:00
|
|
|
store?: Store<StoreState, StoreAction>;
|
2021-08-31 01:18:02 +03:00
|
|
|
persistor?: Persistor;
|
2019-01-03 17:14:25 +03:00
|
|
|
|
2020-08-01 21:21:04 +03:00
|
|
|
UNSAFE_componentWillMount() {
|
2021-09-06 21:29:41 +03:00
|
|
|
const { store, persistor } = configureStore(
|
|
|
|
(store: Store<StoreState, StoreAction>) => {
|
|
|
|
if (store.getState().connection.type !== 'disabled') {
|
|
|
|
store.dispatch({
|
|
|
|
type: CONNECT_REQUEST,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2021-08-31 01:18:02 +03:00
|
|
|
this.store = store;
|
|
|
|
this.persistor = persistor;
|
2019-01-03 17:14:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (!this.store) return null;
|
|
|
|
return (
|
|
|
|
<Provider store={this.store}>
|
2021-08-31 01:18:02 +03:00
|
|
|
<PersistGate loading={null} persistor={this.persistor!}>
|
|
|
|
<App />
|
|
|
|
</PersistGate>
|
2019-01-03 17:14:25 +03:00
|
|
|
</Provider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Root;
|