-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
64 lines (56 loc) · 1.73 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
import React from 'react';
import Navigation from './components/navigation';
import {applyMiddleware, combineReducers, createStore} from 'redux';
import {Provider} from 'react-redux';
import thunk from 'redux-thunk';
import sessionReducer from './features/session/_reducer';
import {AsyncStorage} from 'react-native';
import datesReducer from './features/dates/_reducer';
import permissionsReducer from './features/permissions/_reducer';
import searchReducer from './features/search/_reducer';
import sparksReducer from './features/sparks/_reducer';
import userReducer from './features/users/_reducer';
import {composeWithDevTools} from 'redux-devtools-extension';
console.disableYellowBox = true;
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {store: null};
this._checkSession();
}
async _checkSession() {
let session = await AsyncStorage.getItem('@session');
const location = await AsyncStorage.getItem('@location');
let preloadedState = {};
if (session) {
session = JSON.parse(session);
preloadedState = {
permissions: {location},
session,
};
}
this.setState({
store: createStore(
combineReducers({
session: sessionReducer,
dates: datesReducer,
permissions: permissionsReducer,
search: searchReducer,
sparks: sparksReducer,
users: userReducer,
}),
preloadedState,
composeWithDevTools(applyMiddleware(thunk)),
),
});
}
render() {
if (!this.state.store) return null;
window.store = this.state.store;
return (
<Provider store={this.state.store}>
<Navigation />
</Provider>
);
}
}