Updated reducer for editorial workflow

This commit is contained in:
Cássio Zen 2016-09-13 04:09:52 -03:00
parent f51525baaa
commit 165c758bb9
4 changed files with 22 additions and 10 deletions

View File

@ -17,17 +17,17 @@ export const UNPUBLISHED_ENTRIES_FAILURE = 'UNPUBLISHED_ENTRIES_FAILURE';
* Simple Action Creators (Internal) * Simple Action Creators (Internal)
*/ */
function unpublishedEntryLoading(collection, slug) { function unpublishedEntryLoading(status, slug) {
return { return {
type: UNPUBLISHED_ENTRY_REQUEST, type: UNPUBLISHED_ENTRY_REQUEST,
payload: { collection, slug } payload: { status, slug }
}; };
} }
function unpublishedEntryLoaded(entry) { function unpublishedEntryLoaded(status, entry) {
return { return {
type: UNPUBLISHED_ENTRY_SUCCESS, type: UNPUBLISHED_ENTRY_SUCCESS,
payload: { entry } payload: { status, entry }
}; };
} }
@ -69,13 +69,13 @@ export function init() {
* Exported Thunk Action Creators * Exported Thunk Action Creators
*/ */
export function loadUnpublishedEntry(collection, slug) { export function loadUnpublishedEntry(collection, status, slug) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const backend = currentBackend(state.config); const backend = currentBackend(state.config);
dispatch(unpublishedEntryLoading(collection, slug)); dispatch(unpublishedEntryLoading(status, slug));
backend.unpublishedEntry(collection, slug) backend.unpublishedEntry(collection, slug)
.then((entry) => dispatch(unpublishedEntryLoaded(entry))); .then((entry) => dispatch(unpublishedEntryLoaded(status, entry)));
}; };
} }

View File

@ -57,7 +57,7 @@ class EntryPage extends React.Component {
const { const {
entry, entryDraft, boundGetMedia, collection, changeDraft, addMedia, removeMedia entry, entryDraft, boundGetMedia, collection, changeDraft, addMedia, removeMedia
} = this.props; } = this.props;
console.log(entry)
if (entryDraft == null || entryDraft.get('entry') == undefined || entry && entry.get('isFetching')) { if (entryDraft == null || entryDraft.get('entry') == undefined || entry && entry.get('isFetching')) {
return <div>Loading...</div>; return <div>Loading...</div>;
} }

View File

@ -35,8 +35,9 @@ export default function EntryPageHOC(EntryPage) {
const returnObj = {}; const returnObj = {};
if (unpublishedEntry) { if (unpublishedEntry) {
// Overwrite loadEntry to loadUnpublishedEntry // Overwrite loadEntry to loadUnpublishedEntry
const status = ownProps.params.status;
returnObj.loadEntry = (collection, slug) => { returnObj.loadEntry = (collection, slug) => {
dispatch(loadUnpublishedEntry(collection, slug)); dispatch(loadUnpublishedEntry(collection, status, slug));
}; };
} }
return returnObj; return returnObj;

View File

@ -1,6 +1,6 @@
import { Map, List, fromJS } from 'immutable'; import { Map, List, fromJS } from 'immutable';
import { import {
INIT, UNPUBLISHED_ENTRIES_REQUEST, UNPUBLISHED_ENTRIES_SUCCESS INIT, UNPUBLISHED_ENTRY_REQUEST, UNPUBLISHED_ENTRY_SUCCESS, UNPUBLISHED_ENTRIES_REQUEST, UNPUBLISHED_ENTRIES_SUCCESS
} from '../actions/editorialWorkflow'; } from '../actions/editorialWorkflow';
const unpublishedEntries = (state = null, action) => { const unpublishedEntries = (state = null, action) => {
@ -8,6 +8,17 @@ const unpublishedEntries = (state = null, action) => {
case INIT: case INIT:
// Editorial workflow must be explicitly initiated. // Editorial workflow must be explicitly initiated.
return Map({ entities: Map(), pages: Map() }); 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: case UNPUBLISHED_ENTRIES_REQUEST:
return state.setIn(['pages', 'isFetching'], true); return state.setIn(['pages', 'isFetching'], true);