Moved persisting logic to entryDraft reducer + added tests.

This commit is contained in:
Andrey Okonetchnikov
2016-10-13 14:30:11 +02:00
parent ffe27acc10
commit e53262d92c
6 changed files with 177 additions and 90 deletions

View File

@ -211,13 +211,14 @@ export function createEmptyDraft(collection) {
};
}
export function persistEntry(collection, entry) {
export function persistEntry(collection, entryDraft) {
return (dispatch, getState) => {
const state = getState();
const backend = currentBackend(state.config);
const mediaProxies = entry.get('mediaFiles').map(path => getMedia(state, path));
const mediaProxies = entryDraft.get('mediaFiles').map(path => getMedia(state, path));
const entry = entryDraft.get('entry');
dispatch(entryPersisting(collection, entry));
backend.persistEntry(state.config, collection, entry, mediaProxies.toJS()).then(
backend.persistEntry(state.config, collection, entryDraft, mediaProxies.toJS()).then(
() => dispatch(entryPersisted(collection, entry)),
error => dispatch(entryPersistFail(collection, entry, error))
);