diff --git a/src/actions/entries.js b/src/actions/entries.js index 37cd4f1b..329c7318 100644 --- a/src/actions/entries.js +++ b/src/actions/entries.js @@ -83,12 +83,12 @@ function entryPersisting(collection, entry) { }; } -function entryPersisted(collection, entry) { +function entryPersisted(persistedEntry, persistedMediaFiles) { return { type: ENTRY_PERSIST_SUCCESS, payload: { - collection: collection, - entry: entry + persistedEntry: persistedEntry, + persistedMediaFiles: persistedMediaFiles } }; } @@ -158,7 +158,9 @@ export function persist(collection, entry, mediaFiles) { const backend = currentBackend(state.config); dispatch(entryPersisting(collection, entry)); backend.persist(collection, entry, mediaFiles).then( - (entry) => dispatch(entryPersisted(collection, entry)), + ({persistedEntry, persistedMediaFiles}) => { + dispatch(entryPersisted(persistedEntry, persistedMediaFiles)); + }, (error) => dispatch(entryPersistFail(collection, entry, error)) ); }; diff --git a/src/backends/backend.js b/src/backends/backend.js index 5b8c7108..760c7845 100644 --- a/src/backends/backend.js +++ b/src/backends/backend.js @@ -68,15 +68,18 @@ class Backend { } persist(collection, entryDraft) { - - const entryData = entryDraft.getIn(['entry', 'data']).toJS(); + const entryData = entryDraft.getIn(['entry', 'data']).toObject(); const entryObj = { path: entryDraft.getIn(['entry', 'path']), slug: entryDraft.getIn(['entry', 'slug']), raw: this.entryToRaw(collection, entryData) }; - - return this.implementation.persist(collection, entryObj, entryDraft.get('mediaFiles').toJS()); + return this.implementation.persist(collection, entryObj, entryDraft.get('mediaFiles').toJS()).then( + (response) => ({ + persistedEntry: this.entryWithFormat(collection)(response.persistedEntry), + persistedMediaFiles:response.persistedMediaFiles + }) + ); } entryToRaw(collection, entry) { diff --git a/src/backends/test-repo/implementation.js b/src/backends/test-repo/implementation.js index 4a3a8a32..2afc719b 100644 --- a/src/backends/test-repo/implementation.js +++ b/src/backends/test-repo/implementation.js @@ -52,6 +52,6 @@ export default class TestRepo { const folder = collection.get('folder'); const fileName = entry.path.substring(entry.path.lastIndexOf('/') + 1); window.repoFiles[folder][fileName]['content'] = entry.raw; - return Promise.resolve({collection, entry}); + return Promise.resolve({persistedEntry:entry, persistedMediaFiles:[]}); } } diff --git a/src/reducers/medias.js b/src/reducers/medias.js index 918a170d..e80d24dc 100644 --- a/src/reducers/medias.js +++ b/src/reducers/medias.js @@ -1,5 +1,6 @@ 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) => { @@ -8,6 +9,12 @@ const medias = (state = Map(), action) => { return state.set(action.payload.uri, action.payload); case REMOVE_MEDIA: return state.delete(action.payload); + case ENTRY_PERSIST_SUCCESS: + return state.map((media, uri) => { + if (action.payload.persistedMediaFiles.indexOf(uri) > -1) media.uploaded = true; + return media; + }); + default: return state; } diff --git a/src/valueObjects/MediaProxy.js b/src/valueObjects/MediaProxy.js index 949e79d7..13e6742c 100644 --- a/src/valueObjects/MediaProxy.js +++ b/src/valueObjects/MediaProxy.js @@ -9,6 +9,6 @@ export default function MediaProxy(value, file, uploaded = false) { this.uploaded = uploaded; this.uri = config.media_folder && !uploaded ? config.media_folder + '/' + value : value; this.toString = function() { - return uploaded ? this.uri : window.URL.createObjectURL(this.file, {oneTimeOnly: true}); + return this.uploaded ? this.uri : window.URL.createObjectURL(this.file, {oneTimeOnly: true}); }; }