2016-08-19 13:57:50 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Content
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2016-08-24 15:09:42 +02:00
|
|
|
import styles from './styles.scss';
|
2016-08-23 13:49:15 +02:00
|
|
|
import { createSelector } from 'reselect';
|
2016-08-26 13:28:12 +02:00
|
|
|
import { selectPlugins } from 'containers/App/selectors';
|
2016-08-19 13:57:50 +02:00
|
|
|
|
|
|
|
export class Content extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
|
|
|
render() {
|
2016-08-23 13:49:15 +02:00
|
|
|
let plugin;
|
|
|
|
|
2016-08-26 14:35:59 +02:00
|
|
|
// Detect plugin according to params
|
2016-08-23 13:49:15 +02:00
|
|
|
this.props.plugins.map(p => {
|
2016-08-26 14:35:59 +02:00
|
|
|
if (this.props.params.plugin === p.id) {
|
|
|
|
plugin = p;
|
|
|
|
}
|
2016-08-30 14:05:33 +02:00
|
|
|
return p;
|
2016-08-23 13:49:15 +02:00
|
|
|
});
|
|
|
|
|
2016-08-26 14:35:59 +02:00
|
|
|
let content;
|
2016-08-30 10:53:03 +02:00
|
|
|
if (!this.props.params.plugin) {
|
2016-08-30 14:05:33 +02:00
|
|
|
content = <p>Home</p>;
|
2016-08-30 10:53:03 +02:00
|
|
|
} else if (!plugin) {
|
2016-08-30 14:05:33 +02:00
|
|
|
content = <p>Unknown plugin.</p>;
|
2016-08-26 14:35:59 +02:00
|
|
|
} else {
|
|
|
|
const Elem = plugin.mainComponent;
|
|
|
|
content = <Elem plugin={plugin}></Elem>;
|
|
|
|
}
|
2016-08-23 13:49:15 +02:00
|
|
|
|
2016-08-19 13:57:50 +02:00
|
|
|
return (
|
|
|
|
<div className={styles.content}>
|
2016-08-26 14:35:59 +02:00
|
|
|
{content}
|
2016-08-19 13:57:50 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-23 13:49:15 +02:00
|
|
|
Content.propTypes = {
|
|
|
|
plugins: React.PropTypes.object,
|
|
|
|
onRegisterPluginClicked: React.PropTypes.func,
|
2016-08-30 14:05:33 +02:00
|
|
|
params: React.PropTypes.func,
|
2016-08-23 13:49:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = createSelector(
|
|
|
|
selectPlugins(),
|
|
|
|
(plugins) => ({ plugins })
|
|
|
|
);
|
2016-08-19 13:57:50 +02:00
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return {
|
|
|
|
dispatch,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-08-23 13:49:15 +02:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Content);
|