-
Notifications
You must be signed in to change notification settings - Fork 15
/
app.js
107 lines (96 loc) · 3.24 KB
/
app.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* This is the entry file for the application
*/
import '@babel/polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { ConnectedRouter } from 'connected-react-router';
import history from 'utils/history';
import 'katex/dist/katex.min.css';
import 'highlight.js/styles/atom-one-dark.css';
import 'sanitize.css/sanitize.css';
import App from 'containers/App';
import CommunicationProvider from 'containers/CommunicationProvider';
import LanguageProvider from 'containers/LanguageProvider';
import '!file-loader?name=[name].[ext]!./images/favicon.ico';
import 'file-loader?name=.htaccess!./.htaccess'; // eslint-disable-line import/extensions
import 'config.json'; // eslint-disable-line import/extensions
import 'bootstrap/dist/css/bootstrap.css';
import configureStore from './configureStore';
import { translationMessages } from './i18n';
const initialState = {}; // @todo load local storage
const store = configureStore(initialState, history);
const MOUNT_NODE = document.getElementById('app');
// Main render
const render = (messages) => {
ReactDOM.render(
<Provider store={store}>
<CommunicationProvider store={store}>
<LanguageProvider messages={messages}>
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
</LanguageProvider>
</CommunicationProvider>
</Provider>,
MOUNT_NODE,
);
};
// Add dev mode helpers
if (module.hot) {
module.hot.accept(['./i18n', 'containers/App'], () => {
ReactDOM.unmountComponentAtNode(MOUNT_NODE);
render(translationMessages);
});
}
// Initialize internationization
if (!window.Intl) {
new Promise((resolve) => {
resolve(import('intl'));
})
.then(() =>
Promise.all([
import('intl/locale-data/jsonp/en'),
import('intl/locale-data/jsonp/ar'),
import('intl/locale-data/jsonp/bn'),
import('intl/locale-data/jsonp/de'),
import('intl/locale-data/jsonp/el'),
import('intl/locale-data/jsonp/es'),
import('intl/locale-data/jsonp/fa'),
import('intl/locale-data/jsonp/fi'),
import('intl/locale-data/jsonp/fr'),
import('intl/locale-data/jsonp/hi'),
import('intl/locale-data/jsonp/id'),
import('intl/locale-data/jsonp/it'),
import('intl/locale-data/jsonp/ja'),
import('intl/locale-data/jsonp/pt'),
import('intl/locale-data/jsonp/ru'),
import('intl/locale-data/jsonp/tr'),
import('intl/locale-data/jsonp/zh'),
]),
) // eslint-disable-line prettier/prettier
.then(() => render(translationMessages))
.catch((err) => {
throw err;
});
} else {
render(translationMessages);
}
// Create the main service worker
if (process.env.NODE_ENV === 'production') {
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker
.register('/sw.js')
// eslint-disable-next-line no-unused-vars
.then((registration) => {
// console.log('SW registered: ', registration);
})
.catch((registrationError) => {
// eslint-disable-next-line no-console
console.log('SW registration failed: ', registrationError);
});
});
}
}