-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (31 loc) · 1.1 KB
/
index.js
File metadata and controls
36 lines (31 loc) · 1.1 KB
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
import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from 'react-redux';
import './index.css';
import AppBase from './App';
import registerServiceWorker from './registerServiceWorker';
import store from './store';
import {receiveBoats, setCurrentBoat, receiveAuth} from './actions';
import canEvenNav from './connectors/canEvenNav';
import hasAuth from './connectors/hasAuth';
import mockBoats from './mocks/boats.json';
const App = hasAuth(canEvenNav(AppBase));
if (sessionStorage.getItem('auth')) {
store.dispatch(receiveAuth(JSON.parse(sessionStorage.getItem('auth'))));
}
store.dispatch((dispatch, _, authFetch) => {
const boatReq = process.env.NODE_ENV === 'development' ? Promise.resolve(mockBoats)
: authFetch('/boats.json').then(r => r.json())
boatReq.then(json => {
store.dispatch(receiveBoats(json));
store.dispatch(setCurrentBoat(json.images[Math.floor(Math.random() * json.images.length)].path));
});
})
function reRender() {
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>, document.getElementById('root'));
}
reRender();
registerServiceWorker();