-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (52 loc) · 1.75 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 from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import { Provider } from 'react-redux'
import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk';
import { podcastApp } from './reducers/podcastApp'
import registerServiceWorker from './registerServiceWorker';
import './index.css';
import { PodcastPage } from './components/podcastPage/PodcastPage';
import { PreviewsPage } from './components/previewsPage/PreviewsPage';
import { HowItWorks } from './components/howItWorksPage/HowItWorks';
import { ConnectedPodcastPlayer } from './components/PodcastPlayer';
import { getUserID } from './utils/getUserID';
import { setUserID } from './actions';
const store = createStore(
podcastApp,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
applyMiddleware(thunk)
);
const dbPromise = userID => new Promise((resolve, reject) => {
const open = indexedDB.open('db', 1);
open.onupgradeneeded = e => {
open.result.createObjectStore('s');
};
open.onsuccess = e => {
const s = open.result.transaction('s', 'readwrite').objectStore('s');
s.put(userID, 'userID');
resolve();
};
})
getUserID().then(id => {
store.dispatch(setUserID(id));
return dbPromise(id);
});
ReactDOM.render(
<BrowserRouter>
<Provider
store={store}
>
<div>
<Switch>
<Route exact path='/' component={PreviewsPage} />
<Route path='/podcast/:id?' component={PodcastPage} />
<Route path='/howItWorks' component={HowItWorks} />
</Switch>
<ConnectedPodcastPlayer />
</div>
</Provider>
</BrowserRouter>
, document.getElementById('root'));
registerServiceWorker();