From 9f220181b3d9b95d1acd9a607b418f2d93a5f703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A1ssio=20Zen?= Date: Tue, 19 Jul 2016 19:42:37 -0300 Subject: [PATCH] Set mediaProxy objects as uploaded @ implementation --- src/actions/entries.js | 12 ++++++------ src/backends/backend.js | 8 +------- src/backends/test-repo/implementation.js | 5 +++-- src/reducers/medias.js | 6 ------ 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/actions/entries.js b/src/actions/entries.js index 8e13349b..0f49031a 100644 --- a/src/actions/entries.js +++ b/src/actions/entries.js @@ -70,7 +70,7 @@ function entriesFailed(collection, error) { type: ENTRIES_FAILURE, error: 'Failed to load entries', payload: error.toString(), - meta: {collection: collection.get('name')} + meta: { collection: collection.get('name') } }; } @@ -84,12 +84,12 @@ function entryPersisting(collection, entry) { }; } -function entryPersisted(persistedEntry, persistedMediaFiles) { +function entryPersisted(collection, entry) { return { type: ENTRY_PERSIST_SUCCESS, payload: { - persistedEntry: persistedEntry, - persistedMediaFiles: persistedMediaFiles + collection: collection, + entry: entry } }; } @@ -161,8 +161,8 @@ export function persistEntry(collection, entry) { dispatch(entryPersisting(collection, entry)); backend.persistEntry(collection, entry, MediaProxies.toJS()).then( - ({ persistedEntry, persistedMediaFiles }) => { - dispatch(entryPersisted(persistedEntry, persistedMediaFiles)); + () => { + dispatch(entryPersisted(collection, entry)); }, (error) => dispatch(entryPersistFail(collection, entry, error)) ); diff --git a/src/backends/backend.js b/src/backends/backend.js index fd8f0450..e66ab9cd 100644 --- a/src/backends/backend.js +++ b/src/backends/backend.js @@ -79,13 +79,7 @@ class Backend { collection.get('label') + ' “' + entryDraft.getIn(['entry', 'data', 'title']) + '”'; - return this.implementation.persistEntry(collection, entryObj, MediaFiles, { commitMessage }) - .then( - (response) => ({ - persistedEntry: this.entryWithFormat(collection)(response.persistedEntry), - persistedMediaFiles:response.persistedMediaFiles - }) - ); + return this.implementation.persistEntry(collection, entryObj, MediaFiles, { commitMessage }); } entryToRaw(collection, entry) { diff --git a/src/backends/test-repo/implementation.js b/src/backends/test-repo/implementation.js index a97210b6..c4f41080 100644 --- a/src/backends/test-repo/implementation.js +++ b/src/backends/test-repo/implementation.js @@ -20,7 +20,7 @@ export default class TestRepo { } authenticate(state) { - return Promise.resolve({email: state.email}); + return Promise.resolve({ email: state.email }); } entries(collection) { @@ -52,6 +52,7 @@ export default class TestRepo { const folder = entry.path.substring(0, entry.path.lastIndexOf('/')); const fileName = entry.path.substring(entry.path.lastIndexOf('/') + 1); window.repoFiles[folder][fileName]['content'] = entry.raw; - return Promise.resolve({ persistedEntry:entry, persistedMediaFiles:[] }); + mediaFiles.forEach(media => media.uploaded = true); + return Promise.resolve(); } } diff --git a/src/reducers/medias.js b/src/reducers/medias.js index 0b502c22..c0cfaa34 100644 --- a/src/reducers/medias.js +++ b/src/reducers/medias.js @@ -1,6 +1,5 @@ import { Map } from 'immutable'; import { ADD_MEDIA, REMOVE_MEDIA } from '../actions/media'; -import { ENTRY_PERSIST_SUCCESS } from '../actions/entries'; import MediaProxy from '../valueObjects/MediaProxy'; const medias = (state = Map(), action) => { @@ -9,11 +8,6 @@ const medias = (state = Map(), action) => { return state.set(action.payload.path, action.payload); case REMOVE_MEDIA: return state.delete(action.payload); - case ENTRY_PERSIST_SUCCESS: - return state.map((media, path) => { - if (action.payload.persistedMediaFiles.indexOf(path) > -1) media.uploaded = true; - return media; - }); default: return state;