-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
102 lines (90 loc) · 2.76 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
/**
* React application entry point
*
* - starts application
* - configures app store
* - sets up app routes
* - renders app according to route
* - remembers hash/route changes
* - ties in global styles
*
*/
/* eslint-disable import/no-extraneous-dependencies */
/*
issue with react-hot-loader:
even tho only used in development eslint has no way to tell that and outputs an error
*/
// vendor
import React from 'react';
import ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import { Provider } from 'react-redux';
import { routeSetup, getHash, getHashParameters } from 'react-hash-route';
import { ThemeProvider } from 'styled-components';
// store
import configureStore from 'store';
// containers
import App from 'containers/App';
import PathFocusAreas from 'containers/PathFocusAreas';
import PathFocusAreaSingle from 'containers/PathFocusAreaSingle';
import PathInsights from 'containers/PathInsights';
import PathServices from 'containers/PathServices';
import PathAssets from 'containers/PathAssets';
import PathAbout from 'containers/PathAbout';
import PathNotFound from 'containers/PathNotFound';
import { updateLocation } from 'containers/App/actions';
import { THEME } from 'containers/App/constants';
// utils
import { queryObject } from 'utils/queries';
// Styles
// import react-vis styles
import 'react-vis/dist/styles/legends.scss';
import 'react-vis/dist/styles/plot.scss';
// global application styles & resets
import './global-styles';
// configure app store
const store = configureStore();
// Map hash path to react component
// see also containers/App/constants NAVITEMS
const pathComponentMap = {
'': <PathFocusAreas />, // focus areas
'focus-area': <PathFocusAreaSingle />,
insights: <PathInsights />,
services: <PathServices />,
assets: <PathAssets />,
about: <PathAbout />,
'not-found': <PathNotFound />,
};
/**
* Render React application and attach to 'ogdd-root' element.
* Also records current location in store
* @param {Component} Component main react component
*/
const render = (Component) => {
// remember current hash location in store
store.dispatch(updateLocation({
path: getHash(),
query: queryObject(getHashParameters()),
}));
// render DOM
ReactDOM.render(
<AppContainer>
<Provider store={store}>
<ThemeProvider
theme={THEME}
>
<Component
component={pathComponentMap[getHash() || ''] || pathComponentMap['not-found']}
/>
</ThemeProvider>
</Provider>
</AppContainer>,
document.getElementById('ogdd-root'),
);
};
// start the application with route setup, and component
const start = () => routeSetup(() => render(App));
start();
if (module.hot) {
module.hot.accept('/', () => start());
}