-
Notifications
You must be signed in to change notification settings - Fork 234
/
AppContainer.jsx
95 lines (86 loc) · 2.65 KB
/
AppContainer.jsx
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
import React, { Component } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { MuiThemeProvider } from '@material-ui/core/styles';
import LinearProgress from '@material-ui/core/LinearProgress';
import LeftContainer from './LeftContainer.jsx';
import MainContainer from './MainContainer.jsx';
import RightContainer from './RightContainer.jsx';
import convertIdsToObjs from '../utils/convertIdsToObjs.util';
import theme from '../components/theme';
import { loadInitData } from '../actions/components';
const mapStateToProps = store => ({
components: store.workspace.components,
totalComponents: store.workspace.totalComponents,
focusComponent: store.workspace.focusComponent,
loading: store.workspace.loading,
});
const mapDispatchToProps = { loadInitData };
class AppContainer extends Component {
state = {
width: 25,
rightColumnOpen: true,
}
collapseColumn = () => {
if (this.state.width === 25) {
this.setState({
width: 0,
rightColumnOpen: false,
});
} else {
this.setState({
width: 25,
rightColumnOpen: true,
});
}
}
componentDidMount() {
this.props.loadInitData();
}
render() {
const {
components,
totalComponents,
focusComponent,
loading,
} = this.props;
const { width, rightColumnOpen } = this.state;
const updatedComponents = convertIdsToObjs(components);
return (
<MuiThemeProvider theme={theme}>
<div className='app-container'>
<LeftContainer
components={updatedComponents}
totalComponents={totalComponents}
focusComponent={focusComponent}
/>
<MainContainer
components={updatedComponents}
collapseColumn={this.collapseColumn}
width={width}
rightColumnOpen={rightColumnOpen}
totalComponents={totalComponents}
/>
<RightContainer
width={width}
components={updatedComponents}
rightColumnOpen={rightColumnOpen}
focusComponent={focusComponent}
/>
{
loading ? <div style={{ alignSelf: 'flex-end', position: 'fixed', width: '100%' }}>
<LinearProgress color="secondary" /></div> : null
}
</div>
</MuiThemeProvider>
);
}
}
export default connect(mapStateToProps, mapDispatchToProps)(AppContainer);
AppContainer.propTypes = {
components: PropTypes.array.isRequired,
totalComponents: PropTypes.number.isRequired,
focusComponent: PropTypes.object.isRequired,
loadInitData: PropTypes.func.isRequired,
loading: PropTypes.bool,
};