diff --git a/src/actions/editorialWorkflow.js b/src/actions/editorialWorkflow.js index ee44f857..36187bdf 100644 --- a/src/actions/editorialWorkflow.js +++ b/src/actions/editorialWorkflow.js @@ -17,17 +17,17 @@ export const UNPUBLISHED_ENTRIES_FAILURE = 'UNPUBLISHED_ENTRIES_FAILURE'; * Simple Action Creators (Internal) */ -function unpublishedEntryLoading(collection, slug) { +function unpublishedEntryLoading(status, slug) { return { type: UNPUBLISHED_ENTRY_REQUEST, - payload: { collection, slug } + payload: { status, slug } }; } -function unpublishedEntryLoaded(entry) { +function unpublishedEntryLoaded(status, entry) { return { type: UNPUBLISHED_ENTRY_SUCCESS, - payload: { entry } + payload: { status, entry } }; } @@ -69,13 +69,13 @@ export function init() { * Exported Thunk Action Creators */ -export function loadUnpublishedEntry(collection, slug) { +export function loadUnpublishedEntry(collection, status, slug) { return (dispatch, getState) => { const state = getState(); const backend = currentBackend(state.config); - dispatch(unpublishedEntryLoading(collection, slug)); + dispatch(unpublishedEntryLoading(status, slug)); backend.unpublishedEntry(collection, slug) - .then((entry) => dispatch(unpublishedEntryLoaded(entry))); + .then((entry) => dispatch(unpublishedEntryLoaded(status, entry))); }; } diff --git a/src/containers/EntryPage.js b/src/containers/EntryPage.js index ecb2cda2..1693b587 100644 --- a/src/containers/EntryPage.js +++ b/src/containers/EntryPage.js @@ -57,7 +57,7 @@ class EntryPage extends React.Component { const { entry, entryDraft, boundGetMedia, collection, changeDraft, addMedia, removeMedia } = this.props; - console.log(entry) + if (entryDraft == null || entryDraft.get('entry') == undefined || entry && entry.get('isFetching')) { return
Loading...
; } diff --git a/src/containers/editorialWorkflow/EntryPageHOC.js b/src/containers/editorialWorkflow/EntryPageHOC.js index 4d958a14..1840c210 100644 --- a/src/containers/editorialWorkflow/EntryPageHOC.js +++ b/src/containers/editorialWorkflow/EntryPageHOC.js @@ -35,8 +35,9 @@ export default function EntryPageHOC(EntryPage) { const returnObj = {}; if (unpublishedEntry) { // Overwrite loadEntry to loadUnpublishedEntry + const status = ownProps.params.status; returnObj.loadEntry = (collection, slug) => { - dispatch(loadUnpublishedEntry(collection, slug)); + dispatch(loadUnpublishedEntry(collection, status, slug)); }; } return returnObj; diff --git a/src/reducers/editorialWorkflow.js b/src/reducers/editorialWorkflow.js index fb5a96f5..81bdc980 100644 --- a/src/reducers/editorialWorkflow.js +++ b/src/reducers/editorialWorkflow.js @@ -1,6 +1,6 @@ import { Map, List, fromJS } from 'immutable'; import { - INIT, UNPUBLISHED_ENTRIES_REQUEST, UNPUBLISHED_ENTRIES_SUCCESS + INIT, UNPUBLISHED_ENTRY_REQUEST, UNPUBLISHED_ENTRY_SUCCESS, UNPUBLISHED_ENTRIES_REQUEST, UNPUBLISHED_ENTRIES_SUCCESS } from '../actions/editorialWorkflow'; const unpublishedEntries = (state = null, action) => { @@ -8,6 +8,17 @@ const unpublishedEntries = (state = null, action) => { case INIT: // Editorial workflow must be explicitly initiated. return Map({ entities: Map(), pages: Map() }); + + case UNPUBLISHED_ENTRY_REQUEST: + return state.setIn(['entities', `${action.payload.status}.${action.payload.slug}`, 'isFetching'], true); + + case UNPUBLISHED_ENTRY_SUCCESS: + return state.setIn( + ['entities', `${action.payload.status}.${action.payload.entry.slug}`], + fromJS(action.payload.entry) + ); + + case UNPUBLISHED_ENTRIES_REQUEST: return state.setIn(['pages', 'isFetching'], true);