2016-09-06 13:04:17 -03:00
|
|
|
import { currentBackend } from '../backends/backend';
|
|
|
|
import { EDITORIAL_WORKFLOW } from '../constants/publishModes';
|
|
|
|
/*
|
|
|
|
* Contant Declarations
|
|
|
|
*/
|
2016-09-08 16:18:38 -03:00
|
|
|
export const INIT = 'init';
|
2016-09-13 03:59:48 -03:00
|
|
|
|
|
|
|
export const UNPUBLISHED_ENTRY_REQUEST = 'UNPUBLISHED_ENTRY_REQUEST';
|
|
|
|
export const UNPUBLISHED_ENTRY_SUCCESS = 'UNPUBLISHED_ENTRY_SUCCESS';
|
|
|
|
|
2016-09-06 13:04:17 -03:00
|
|
|
export const UNPUBLISHED_ENTRIES_REQUEST = 'UNPUBLISHED_ENTRIES_REQUEST';
|
|
|
|
export const UNPUBLISHED_ENTRIES_SUCCESS = 'UNPUBLISHED_ENTRIES_SUCCESS';
|
|
|
|
export const UNPUBLISHED_ENTRIES_FAILURE = 'UNPUBLISHED_ENTRIES_FAILURE';
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simple Action Creators (Internal)
|
|
|
|
*/
|
2016-09-13 03:59:48 -03:00
|
|
|
|
|
|
|
function unpublishedEntryLoading(collection, slug) {
|
|
|
|
return {
|
|
|
|
type: UNPUBLISHED_ENTRY_REQUEST,
|
|
|
|
payload: { collection, slug }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function unpublishedEntryLoaded(entry) {
|
|
|
|
return {
|
|
|
|
type: UNPUBLISHED_ENTRY_SUCCESS,
|
|
|
|
payload: { entry }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-09-06 13:04:17 -03:00
|
|
|
function unpublishedEntriesLoading() {
|
|
|
|
return {
|
|
|
|
type: UNPUBLISHED_ENTRIES_REQUEST
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function unpublishedEntriesLoaded(entries, pagination) {
|
|
|
|
return {
|
|
|
|
type: UNPUBLISHED_ENTRIES_SUCCESS,
|
|
|
|
payload: {
|
|
|
|
entries: entries,
|
|
|
|
pages: pagination
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function unpublishedEntriesFailed(error) {
|
|
|
|
return {
|
|
|
|
type: UNPUBLISHED_ENTRIES_FAILURE,
|
|
|
|
error: 'Failed to load entries',
|
|
|
|
payload: error.toString(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-09-08 16:18:38 -03:00
|
|
|
/*
|
|
|
|
* Exported simple Action Creators
|
|
|
|
*/
|
|
|
|
export function init() {
|
|
|
|
return {
|
|
|
|
type: INIT
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-06 13:04:17 -03:00
|
|
|
/*
|
|
|
|
* Exported Thunk Action Creators
|
|
|
|
*/
|
2016-09-13 03:59:48 -03:00
|
|
|
|
|
|
|
export function loadUnpublishedEntry(collection, slug) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
|
|
|
const backend = currentBackend(state.config);
|
|
|
|
dispatch(unpublishedEntryLoading(collection, slug));
|
|
|
|
backend.unpublishedEntry(collection, slug)
|
|
|
|
.then((entry) => dispatch(unpublishedEntryLoaded(entry)));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-09-06 13:04:17 -03:00
|
|
|
export function loadUnpublishedEntries() {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
2016-09-06 17:18:27 -03:00
|
|
|
if (state.config.get('publish_mode') !== EDITORIAL_WORKFLOW) return;
|
2016-09-06 13:04:17 -03:00
|
|
|
const backend = currentBackend(state.config);
|
|
|
|
dispatch(unpublishedEntriesLoading());
|
|
|
|
backend.unpublishedEntries().then(
|
|
|
|
(response) => dispatch(unpublishedEntriesLoaded(response.entries, response.pagination)),
|
|
|
|
(error) => dispatch(unpublishedEntriesFailed(error))
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|