-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (42 loc) · 1.4 KB
/
index.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
import React from 'react';
import ReactDOM from 'react-dom';
import thunkMiddleware from 'redux-thunk'
import { createLogger } from 'redux-logger'
import { createStore, applyMiddleware } from 'redux'
import './index.css';
import './App.css';
import storageAvailable from "./helpers/storage_available.js";
import Root from './containers/root.js';
import registerServiceWorker from './registerServiceWorker';
import rootReducer from './reducers/reducer.js'
import {fetchItemsIfNeeded, setUserFromStorage} from "./actions/actions.js"
import {getDBItemsAndBags} from './actions/item_actions.js'
const loggerMiddleware = createLogger();
const store = createStore(
rootReducer,
applyMiddleware(
thunkMiddleware,
loggerMiddleware
)
)
if (storageAvailable('localStorage')) {
// Yippee! We can use localStorage awesomeness
console.log('local storage is available');
let storedUser = JSON.parse( localStorage.getItem('User'))
console.log(storedUser)
if(storedUser.name ) {
store.dispatch( setUserFromStorage(storedUser))
store.dispatch( getDBItemsAndBags() )
}
}
else {
// Too bad, no localStorage for us
console.log('no local storage')
store.dispatch(fetchItemsIfNeeded('test'))
.then(function() {
store.dispatch(getDBItemsAndBags())
console.log('now to get db stuff')
})
}
ReactDOM.render(<Root store={store}/>, document.getElementById('root'));
registerServiceWorker();