import React, { PropTypes } from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { connect } from 'react-redux'; import { loadEntry, createDraft, discardDraft, changeDraft, persist } from '../actions/entries'; import { addMedia, removeMedia } from '../actions/media'; import { selectEntry, getMedia } from '../reducers'; import EntryEditor from '../components/EntryEditor'; class EntryPage extends React.Component { constructor(props) { super(props); this.props.loadEntry(props.collection, props.slug); this.handlePersist = this.handlePersist.bind(this); } componentDidMount() { if (this.props.entry) { this.props.createDraft(this.props.entry); } } componentWillReceiveProps(nextProps) { if (this.props.entry !== nextProps.entry && !nextProps.entry.get('isFetching')) { this.props.createDraft(nextProps.entry); } } componentWillUnmount() { this.props.discardDraft(); } handlePersist() { this.props.persist(this.props.collection, this.props.entryDraft); } render() { const { entry, entryDraft, boundGetMedia, collection, changeDraft, addMedia, removeMedia } = this.props; if (entry == null || entryDraft.get('entry') == undefined || entry.get('isFetching')) { return