-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (45 loc) · 1.62 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
54
55
56
57
import React, { Fragment } from 'react';
import ReactDOM from 'react-dom';
import { Provider } from "react-redux";
import { handleActions, combineActions } from "redux-actions";
import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import { applyMiddleware, createStore } from "redux";
import { composeWithDevTools } from "redux-devtools-extension";
import promiseMiddleware from "redux-promise";
import thunk from "redux-thunk";
import App from './App';
import './index.css';
import appReducer from "./reducers";
import { login, logout, register } from "./reducers/auth.actions";
import { getListings } from "./reducers/listings.actions";
import { getTasks } from "./reducers/tasks.actions";
import registerServiceWorker from './registerServiceWorker';
const loader = handleActions(
{
[combineActions(login, register)]: (state) => {
store.dispatch(getListings());
store.dispatch(getTasks());
return state;
},
[logout]: () => undefined,
},
{}
);
const rootReducer = (state, action) => appReducer(loader(state, action), action);
const store = createStore(rootReducer, composeWithDevTools(applyMiddleware(promiseMiddleware, thunk)));
const loadingTask = store.getState().auth.isAuthenticated
? Promise.all([store.dispatch(getListings()), store.dispatch(getTasks())]).catch(() => Promise.resolve(false))
: Promise.resolve(true);
loadingTask.then(() => {
ReactDOM.render(
<Fragment>
<ToastContainer/>
<Provider store={store}>
<App/>
</Provider>
</Fragment>,
document.getElementById('root')
);
});
registerServiceWorker();