Handle formats better

This commit is contained in:
Mathias Biilmann Christensen
2016-09-13 14:53:50 +02:00
12 changed files with 171 additions and 45 deletions

View File

@ -6,7 +6,7 @@ import { selectEntries } from '../reducers';
import { Loader } from '../components/UI';
import EntryListing from '../components/EntryListing';
import styles from './CollectionPage.css';
import EditorialWorkflow from './EditorialWorkflowHoC';
import CollectionPageHOC from './editorialWorkflow/CollectionPageHOC';
class DashboardPage extends React.Component {
componentDidMount() {
@ -50,7 +50,7 @@ DashboardPage.propTypes = {
* Instead of checking the publish mode everywhere to dispatch & render the additional editorial workflow stuff,
* We delegate it to a Higher Order Component
*/
DashboardPage = EditorialWorkflow(DashboardPage);
DashboardPage = CollectionPageHOC(DashboardPage);
function mapStateToProps(state, ownProps) {

View File

@ -12,6 +12,7 @@ import {
import { addMedia, removeMedia } from '../actions/media';
import { selectEntry, getMedia } from '../reducers';
import EntryEditor from '../components/EntryEditor';
import EntryPageHOC from './editorialWorkflow/EntryPageHOC';
class EntryPage extends React.Component {
constructor(props) {
@ -56,6 +57,7 @@ class EntryPage extends React.Component {
const {
entry, entryDraft, boundGetMedia, collection, changeDraft, addMedia, removeMedia
} = this.props;
if (entryDraft == null || entryDraft.get('entry') == undefined || entry && entry.get('isFetching')) {
return <div>Loading...</div>;
}
@ -100,6 +102,12 @@ function mapStateToProps(state, ownProps) {
return { collection, collections, newEntry, entryDraft, boundGetMedia, slug, entry };
}
/*
* Instead of checking the publish mode everywhere to dispatch & render the additional editorial workflow stuff,
* We delegate it to a Higher Order Component
*/
EntryPage = EntryPageHOC(EntryPage);
export default connect(
mapStateToProps,
{

View File

@ -1,19 +1,18 @@
import React, { PropTypes } from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { OrderedMap } from 'immutable';
import { init, loadUnpublishedEntries } from '../actions/editorialWorkflow';
import { selectUnpublishedEntries } from '../reducers';
import { EDITORIAL_WORKFLOW, status } from '../constants/publishModes';
import UnpublishedListing from '../components/UnpublishedListing';
import { loadUnpublishedEntries } from '../../actions/editorialWorkflow';
import { selectUnpublishedEntries } from '../../reducers';
import { EDITORIAL_WORKFLOW, status } from '../../constants/publishModes';
import UnpublishedListing from '../../components/UnpublishedListing';
import { connect } from 'react-redux';
export default function EditorialWorkflow(WrappedComponent) {
class EditorialWorkflow extends WrappedComponent {
export default function CollectionPageHOC(CollectionPage) {
class CollectionPageHOC extends CollectionPage {
componentDidMount() {
const { dispatch, isEditorialWorkflow } = this.props;
if (isEditorialWorkflow) {
dispatch(init());
dispatch(loadUnpublishedEntries());
}
super.componentDidMount();
@ -32,7 +31,7 @@ export default function EditorialWorkflow(WrappedComponent) {
}
}
EditorialWorkflow.propTypes = {
CollectionPageHOC.propTypes = {
dispatch: PropTypes.func.isRequired,
isEditorialWorkflow: PropTypes.bool.isRequired,
unpublishedEntries: ImmutablePropTypes.map,
@ -56,5 +55,5 @@ export default function EditorialWorkflow(WrappedComponent) {
return returnObj;
}
return connect(mapStateToProps)(EditorialWorkflow);
return connect(mapStateToProps)(CollectionPageHOC);
}

View File

@ -0,0 +1,47 @@
import React from 'react';
import { EDITORIAL_WORKFLOW } from '../../constants/publishModes';
import { selectUnpublishedEntry } from '../../reducers';
import { loadUnpublishedEntry } from '../../actions/editorialWorkflow';
import { connect } from 'react-redux';
export default function EntryPageHOC(EntryPage) {
class EntryPageHOC extends React.Component {
render() {
return <EntryPage {...this.props}/>;
}
}
function mapStateToProps(state, ownProps) {
const publish_mode = state.config.get('publish_mode');
const isEditorialWorkflow = (publish_mode === EDITORIAL_WORKFLOW);
const unpublishedEntry = ownProps.route && ownProps.route.unpublishedEntry === true;
const returnObj = {};
if (isEditorialWorkflow && unpublishedEntry) {
const status = ownProps.params.status;
const slug = ownProps.params.slug;
const entry = selectUnpublishedEntry(state, status, slug);
returnObj.entry = entry;
returnObj.persistEntry = () => {
// TODO - for now, simply ignore
};
}
return returnObj;
}
function mapDispatchToProps(dispatch, ownProps) {
const unpublishedEntry = ownProps.route && ownProps.route.unpublishedEntry === true;
const returnObj = {};
if (unpublishedEntry) {
// Overwrite loadEntry to loadUnpublishedEntry
const status = ownProps.params.status;
returnObj.loadEntry = (collection, slug) => {
dispatch(loadUnpublishedEntry(collection, status, slug));
};
}
return returnObj;
}
return connect(mapStateToProps, mapDispatchToProps)(EntryPageHOC);
}