forked from mediacloud/web-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·133 lines (125 loc) · 3.59 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import 'core-js/stable';
import 'regenerator-runtime/runtime';
import 'intl';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactGA from 'react-ga';
import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles';
import { IntlProvider } from 'react-intl';
import { Provider } from 'react-redux';
import Router from 'react-router/lib/Router';
import hashHistory from 'react-router/lib/hashHistory';
import { syncHistoryWithStore } from 'react-router-redux';
import Raven from 'raven-js';
import { loginWithCookie } from './actions/userActions';
import getStore from './store';
import { getAppName, getVersion, isProdMode } from './config';
import { getBrandColors } from './styles/colors';
const APP_DOM_ELEMENT_ID = 'app';
const DEFAULT_LOCALE = 'en';
const SENTRY_DSN_CONNECT = process.env.SENTRY_DSN;
function reallyInitializeApp(routes) {
const store = getStore(getAppName());
// Create an enhanced history that syncs navigation events with the store
const history = syncHistoryWithStore(hashHistory, store);
const logPageView = () => {
// only log hits to google analytics when in production mode
if (process.env.NODE_ENV === 'production') {
ReactGA.set({ page: window.location.pathname });
ReactGA.pageview(window.location.pathname);
}
};
const muiTheme = createMuiTheme({
typography: {
useNextVariants: true,
},
palette: {
primary: getBrandColors(),
secondary: getBrandColors(),
},
dialog: {
width: '80%',
},
status: {
info: 'info',
warning: 'warning',
error: 'error',
},
overrides: { // Name of the component ⚛️ / style sheet
MuiButton: {
root: {
padding: '5px 16px',
},
containedPrimary: {
color: 'white',
},
outlined: {
color: getBrandColors().dark,
},
label: {
fontFamily: 'Lato, sans',
fontWeight: 300,
},
},
MuiInput: {
input: {
padding: '8px 0px',
fontFamily: 'Lato, Helvetica, sans',
},
},
MuiModal: {
// paperWidth: '80%',
},
MuiTypography: {
h6: {
fontFamily: 'Lato, Helvetica, sans',
},
},
MuiInputLabel: {
root: {
fontFamily: 'Lato, Helvetica, sans',
},
},
zIndex: {
modal: 900,
},
},
});
const renderApp = () => {
ReactDOM.render(
<ThemeProvider theme={muiTheme}>
<Provider store={store}>
<IntlProvider locale={DEFAULT_LOCALE}>
<Router history={history} onUpdate={logPageView}>
{routes}
</Router>
</IntlProvider>
</Provider>
</ThemeProvider>,
document.getElementById(APP_DOM_ELEMENT_ID)
);
};
// log them in if they have a valid cookie (wait till login attempt complete before rendering app)
store.dispatch(loginWithCookie())
.then(() => renderApp());
}
/**
* Call this from your own appIndex.js with some routes to start up your app. Do not
* refer to this file as an entry point directly.
*/
export default function initializeApp(routes) {
// set up logging when you're in production mode
if (isProdMode()) {
Raven.config(SENTRY_DSN_CONNECT, {
release: getVersion(),
environment: 'production',
logger: getAppName(),
}).install();
// This wraps the app intialization in a Raven context to catch any init errors (as they recommend).
Raven.context(() => {
reallyInitializeApp(routes);
});
} else {
reallyInitializeApp(routes);
}
}