-
Notifications
You must be signed in to change notification settings - Fork 14
/
RulesProvider.js
46 lines (44 loc) · 1.04 KB
/
RulesProvider.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
import { React, Component } from 'Components'
import { connect } from 'react-redux'
import { toPairs } from 'ramda'
export default connect(
state => ({ rulesLoaded: state.rules != null }),
dispatch => ({ setRules: rules => dispatch({ type: 'SET_RULES', rules }) })
)(
class extends Component {
removeLoader() {
// Remove loader
var css = document.createElement('style')
css.type = 'text/css'
css.innerHTML = `
#js {
animation: appear 0.5s;
opacity: 1;
}
#loading {
display: none !important;
}`
document.body.appendChild(css)
}
constructor(props) {
super(props)
if (process.env.NODE_ENV === 'development') {
import('../../data/co2.yaml').then(src => {
this.props.setRules(src.default)
this.removeLoader()
})
} else {
fetch(props.rulesURL, { mode: 'cors' })
.then(response => response.json())
.then(json => {
this.props.setRules(json)
this.removeLoader()
})
}
}
render() {
if (!this.props.rulesLoaded) return null
return this.props.children
}
}
)