-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathAppContainer.react.js
73 lines (65 loc) · 2.02 KB
/
AppContainer.react.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
import {connect} from 'react-redux';
import React from 'react';
import PropTypes from 'prop-types';
import APIController from './APIController.react';
import DocumentTitle from './components/core/DocumentTitle.react';
import Loading from './components/core/Loading.react';
import Toolbar from './components/core/Toolbar.react';
import Reloader from './components/core/Reloader.react';
import {setHooks, setConfig} from './actions/index';
import {type} from 'ramda';
class UnconnectedAppContainer extends React.Component {
constructor(props) {
super(props);
if (
props.hooks.request_pre !== null ||
props.hooks.request_post !== null
) {
props.dispatch(setHooks(props.hooks));
}
}
UNSAFE_componentWillMount() {
const {dispatch} = this.props;
const config = JSON.parse(
document.getElementById('_dash-config').textContent
);
// preset common request params in the config
config.fetch = {
credentials: 'same-origin',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
};
dispatch(setConfig(config));
}
render() {
const {config} = this.props;
if (type(config) === 'Null') {
return <div className="_dash-loading">Loading...</div>;
}
const {show_undo_redo} = config;
return (
<React.Fragment>
{show_undo_redo ? <Toolbar /> : null}
<APIController />
<DocumentTitle />
<Loading />
<Reloader />
</React.Fragment>
);
}
}
UnconnectedAppContainer.propTypes = {
hooks: PropTypes.object,
dispatch: PropTypes.func,
config: PropTypes.object
};
const AppContainer = connect(
state => ({
history: state.history,
config: state.config
}),
dispatch => ({dispatch})
)(UnconnectedAppContainer);
export default AppContainer;