2016-02-25 20:40:35 -08:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2016-05-30 16:55:32 -07:00
|
|
|
import { Map } from 'immutable';
|
2016-06-06 21:53:22 -03:00
|
|
|
import { loadEntry, persist } from '../actions/entries';
|
2016-06-05 01:52:18 -07:00
|
|
|
import { selectEntry } from '../reducers/entries';
|
2016-05-30 16:55:32 -07:00
|
|
|
import EntryEditor from '../components/EntryEditor';
|
2016-02-25 20:40:35 -08:00
|
|
|
|
2016-05-30 17:08:30 -07:00
|
|
|
class EntryPage extends React.Component {
|
2016-06-05 01:52:18 -07:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.props.dispatch(loadEntry(props.collection, props.slug));
|
2016-06-06 21:53:22 -03:00
|
|
|
|
|
|
|
this.handlePersist = this.handlePersist.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
handlePersist(entry, mediaFiles) {
|
|
|
|
this.props.dispatch(persist(this.props.collection, entry, mediaFiles));
|
2016-06-05 01:52:18 -07:00
|
|
|
}
|
|
|
|
|
2016-02-25 20:40:35 -08:00
|
|
|
render() {
|
2016-06-05 01:52:18 -07:00
|
|
|
const { entry, collection } = this.props;
|
|
|
|
if (entry == null || entry.get('isFetching')) {
|
|
|
|
return <div>Loading...</div>;
|
|
|
|
}
|
2016-02-25 20:40:35 -08:00
|
|
|
|
2016-06-05 01:52:18 -07:00
|
|
|
return (
|
|
|
|
<EntryEditor
|
|
|
|
entry={entry || new Map()}
|
|
|
|
collection={collection}
|
2016-06-06 21:53:22 -03:00
|
|
|
onPersist={this.handlePersist}
|
2016-06-05 01:52:18 -07:00
|
|
|
/>
|
|
|
|
);
|
2016-02-25 20:40:35 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state, ownProps) {
|
2016-06-05 01:52:18 -07:00
|
|
|
const { collections } = state;
|
2016-05-30 16:55:32 -07:00
|
|
|
const collection = collections.get(ownProps.params.name);
|
2016-06-05 01:52:18 -07:00
|
|
|
const slug = ownProps.params.slug;
|
|
|
|
const entry = selectEntry(state, collection.get('name'), slug);
|
2016-02-25 20:40:35 -08:00
|
|
|
|
2016-06-05 01:52:18 -07:00
|
|
|
return {collection, collections, slug, entry};
|
2016-02-25 20:40:35 -08:00
|
|
|
}
|
|
|
|
|
2016-05-30 17:08:30 -07:00
|
|
|
export default connect(mapStateToProps)(EntryPage);
|