forked from quran/quran.com-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
74 lines (62 loc) · 2.02 KB
/
client.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
65
66
67
68
69
70
71
72
73
74
/*global document, window, $ */
import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import reactCookie from 'react-cookie';
import Provider from 'react-redux/lib/components/Provider';
import Router from 'react-router/lib/Router';
import match from 'react-router/lib/match';
import browserHistory from 'react-router/lib/browserHistory';
import applyRouterMiddleware from 'react-router/lib/applyRouterMiddleware';
import useScroll from 'react-router-scroll';
import { ReduxAsyncConnect } from 'redux-connect';
import { syncHistoryWithStore } from 'react-router-redux';
import debug from 'debug';
import config from 'config';
import ApiClient from './src/helpers/ApiClient';
import createStore from './src/redux/create';
import routes from './src/routes';
const client = new ApiClient();
const store = createStore(browserHistory, client, window.__data);
const history = syncHistoryWithStore(browserHistory, store);
Raven.config(config.sentryClient).install()
window.quranDebug = debug;
window.ReactDOM = ReactDOM; // For chrome dev tool support
window.clearCookies = function() {
reactCookie.remove('quran');
reactCookie.remove('content');
reactCookie.remove('audio');
reactCookie.remove('isFirstTime');
};
// Init tooltip
if (typeof window !== 'undefined') {
$(function () {
$(document.body).tooltip({
selector: '[data-toggle="tooltip"]',
animation: false
});
});
}
match({ history, routes: routes() }, (error, redirectLocation, renderProps) => {
const component = (
<Router
{...renderProps}
render={(props) => (
<ReduxAsyncConnect
{...props}
helpers={{client}}
filter={item => !item.deferred}
render={applyRouterMiddleware(useScroll())}
/>
)}
/>
);
const mountNode = document.getElementById('app');
debug('client', 'React Rendering');
ReactDOM.render(
<Provider store={store} key="provider">
{component}
</Provider>, mountNode, () => {
debug('client', 'React Rendered');
});
});