99 lines
2.2 KiB
JavaScript
Raw Normal View History

/*
*
* Single
*
*/
import React from 'react';
import { connect } from 'react-redux';
2017-01-26 18:53:52 +01:00
import { createStructuredSelector } from 'reselect';
import Container from 'components/Container';
2017-01-26 18:53:52 +01:00
import {
setCurrentModel,
loadRecord,
2017-01-26 18:53:52 +01:00
} from './actions';
import {
makeSelectRecord,
makeSelectLoading,
2017-01-26 18:53:52 +01:00
} from './selectors';
export class Single extends React.Component { // eslint-disable-line react/prefer-stateless-function
2017-01-26 18:53:52 +01:00
componentWillMount() {
this.props.setCurrentModel(this.props.routeParams.slug.toLowerCase());
this.props.loadRecord(this.props.routeParams.id);
2017-01-26 18:53:52 +01:00
}
render() {
const PluginHeader = this.props.exposedComponents.PluginHeader;
2017-01-26 18:53:52 +01:00
let content;
if (this.props.loading) {
content = (
<div>
<p>Loading...</p>
</div>
);
} else if (this.props.record) {
const items = [];
for(var key in this.props.record) {
items.push(<li key={key}>{key}: {this.props.record[key]}</li>);
}
content = (
<ul>
{items}
</ul>
)
2017-01-26 18:53:52 +01:00
}
return (
<div>
<div className="container-fluid">
<PluginHeader title={{
id: 'plugin-content-manager-title',
defaultMessage: `Content Manager > ${this.props.routeParams.slug}`
}} description={{
id: 'plugin-content-manager-description',
defaultMessage: `Manage your ${this.props.routeParams.slug}`
}} noActions={false}>
</PluginHeader>
<Container>
<p></p>
{content}
</Container>
</div>
</div>
);
}
}
Single.propTypes = {
setCurrentModel: React.PropTypes.func,
loadRecord: React.PropTypes.func,
loading: React.PropTypes.bool,
record: React.PropTypes.oneOfType([
React.PropTypes.object,
React.PropTypes.bool,
]),
};
2017-01-26 18:53:52 +01:00
const mapStateToProps = createStructuredSelector({
record: makeSelectRecord(),
loading: makeSelectLoading(),
2017-01-26 18:53:52 +01:00
});
function mapDispatchToProps(dispatch) {
return {
setCurrentModel: (model) => dispatch(setCurrentModel(model)),
loadRecord: (id) => dispatch(loadRecord(id)),
dispatch,
};
}
export default connect(mapStateToProps, mapDispatchToProps)(Single);