2017-01-17 13:40:59 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* This component is the skeleton around the actual pages, and should only
|
|
|
|
* contain code that should be seen on all pages. (e.g. navigation bar)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2017-03-18 17:34:00 +01:00
|
|
|
import { createStructuredSelector } from 'reselect';
|
|
|
|
import { loadModels } from './actions';
|
2017-05-11 10:54:44 +02:00
|
|
|
import { makeSelectModels, makeSelectLoading } from './selectors';
|
2017-03-18 17:34:00 +01:00
|
|
|
import { connect } from 'react-redux';
|
2017-01-17 13:40:59 +01:00
|
|
|
|
|
|
|
import '../../styles/main.scss';
|
|
|
|
|
2017-05-11 10:54:44 +02:00
|
|
|
class App extends React.Component {
|
2017-03-18 17:34:00 +01:00
|
|
|
componentWillMount() {
|
|
|
|
this.props.loadModels();
|
|
|
|
}
|
|
|
|
|
2017-01-17 13:40:59 +01:00
|
|
|
render() {
|
2017-05-11 10:54:44 +02:00
|
|
|
let content = <div />;
|
2017-05-04 19:05:41 +02:00
|
|
|
|
|
|
|
if (this.props.models) {
|
|
|
|
// Assign plugin component to children
|
2017-05-11 10:54:44 +02:00
|
|
|
content = React.Children.map(this.props.children, child =>
|
|
|
|
React.cloneElement(child, {
|
|
|
|
exposedComponents: this.props.exposedComponents,
|
2017-05-04 19:05:41 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2017-01-20 16:22:57 +01:00
|
|
|
|
2017-01-17 13:40:59 +01:00
|
|
|
return (
|
2017-05-11 10:54:44 +02:00
|
|
|
<div className="content-manager">
|
2017-05-04 19:05:41 +02:00
|
|
|
{React.Children.toArray(content)}
|
2017-03-18 17:34:00 +01:00
|
|
|
</div>
|
2017-01-17 13:40:59 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-03-18 17:34:00 +01:00
|
|
|
|
2017-04-11 15:38:15 +02:00
|
|
|
App.contextTypes = {
|
|
|
|
router: React.PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
2017-03-18 17:34:00 +01:00
|
|
|
App.propTypes = {
|
2017-05-11 10:54:44 +02:00
|
|
|
children: React.PropTypes.node.isRequired,
|
|
|
|
loadModels: React.PropTypes.func.isRequired,
|
|
|
|
exposedComponents: React.PropTypes.object.isRequired,
|
|
|
|
models: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.object,
|
|
|
|
React.PropTypes.bool,
|
|
|
|
]),
|
2017-03-18 17:34:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export function mapDispatchToProps(dispatch) {
|
|
|
|
return {
|
|
|
|
loadModels: () => dispatch(loadModels()),
|
|
|
|
dispatch,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
|
|
models: makeSelectModels(),
|
2017-05-04 19:05:41 +02:00
|
|
|
loading: makeSelectLoading(),
|
2017-03-18 17:34:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Wrap the component to inject dispatch and state into it
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(App);
|