mediaFiles backend persistence structure
This commit is contained in:
parent
1700f98e4e
commit
6ed7e78642
@ -83,12 +83,12 @@ function entryPersisting(collection, entry) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function entryPersisted(collection, entry) {
|
function entryPersisted(persistedEntry, persistedMediaFiles) {
|
||||||
return {
|
return {
|
||||||
type: ENTRY_PERSIST_SUCCESS,
|
type: ENTRY_PERSIST_SUCCESS,
|
||||||
payload: {
|
payload: {
|
||||||
collection: collection,
|
persistedEntry: persistedEntry,
|
||||||
entry: entry
|
persistedMediaFiles: persistedMediaFiles
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -158,7 +158,9 @@ export function persist(collection, entry, mediaFiles) {
|
|||||||
const backend = currentBackend(state.config);
|
const backend = currentBackend(state.config);
|
||||||
dispatch(entryPersisting(collection, entry));
|
dispatch(entryPersisting(collection, entry));
|
||||||
backend.persist(collection, entry, mediaFiles).then(
|
backend.persist(collection, entry, mediaFiles).then(
|
||||||
(entry) => dispatch(entryPersisted(collection, entry)),
|
({persistedEntry, persistedMediaFiles}) => {
|
||||||
|
dispatch(entryPersisted(persistedEntry, persistedMediaFiles));
|
||||||
|
},
|
||||||
(error) => dispatch(entryPersistFail(collection, entry, error))
|
(error) => dispatch(entryPersistFail(collection, entry, error))
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -68,15 +68,18 @@ class Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
persist(collection, entryDraft) {
|
persist(collection, entryDraft) {
|
||||||
|
const entryData = entryDraft.getIn(['entry', 'data']).toObject();
|
||||||
const entryData = entryDraft.getIn(['entry', 'data']).toJS();
|
|
||||||
const entryObj = {
|
const entryObj = {
|
||||||
path: entryDraft.getIn(['entry', 'path']),
|
path: entryDraft.getIn(['entry', 'path']),
|
||||||
slug: entryDraft.getIn(['entry', 'slug']),
|
slug: entryDraft.getIn(['entry', 'slug']),
|
||||||
raw: this.entryToRaw(collection, entryData)
|
raw: this.entryToRaw(collection, entryData)
|
||||||
};
|
};
|
||||||
|
return this.implementation.persist(collection, entryObj, entryDraft.get('mediaFiles').toJS()).then(
|
||||||
return this.implementation.persist(collection, entryObj, entryDraft.get('mediaFiles').toJS());
|
(response) => ({
|
||||||
|
persistedEntry: this.entryWithFormat(collection)(response.persistedEntry),
|
||||||
|
persistedMediaFiles:response.persistedMediaFiles
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
entryToRaw(collection, entry) {
|
entryToRaw(collection, entry) {
|
||||||
|
@ -52,6 +52,6 @@ export default class TestRepo {
|
|||||||
const folder = collection.get('folder');
|
const folder = collection.get('folder');
|
||||||
const fileName = entry.path.substring(entry.path.lastIndexOf('/') + 1);
|
const fileName = entry.path.substring(entry.path.lastIndexOf('/') + 1);
|
||||||
window.repoFiles[folder][fileName]['content'] = entry.raw;
|
window.repoFiles[folder][fileName]['content'] = entry.raw;
|
||||||
return Promise.resolve({collection, entry});
|
return Promise.resolve({persistedEntry:entry, persistedMediaFiles:[]});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { Map } from 'immutable';
|
import { Map } from 'immutable';
|
||||||
import { ADD_MEDIA, REMOVE_MEDIA } from '../actions/media';
|
import { ADD_MEDIA, REMOVE_MEDIA } from '../actions/media';
|
||||||
|
import { ENTRY_PERSIST_SUCCESS } from '../actions/entries';
|
||||||
import MediaProxy from '../valueObjects/MediaProxy';
|
import MediaProxy from '../valueObjects/MediaProxy';
|
||||||
|
|
||||||
const medias = (state = Map(), action) => {
|
const medias = (state = Map(), action) => {
|
||||||
@ -8,6 +9,12 @@ const medias = (state = Map(), action) => {
|
|||||||
return state.set(action.payload.uri, action.payload);
|
return state.set(action.payload.uri, action.payload);
|
||||||
case REMOVE_MEDIA:
|
case REMOVE_MEDIA:
|
||||||
return state.delete(action.payload);
|
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:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,6 @@ export default function MediaProxy(value, file, uploaded = false) {
|
|||||||
this.uploaded = uploaded;
|
this.uploaded = uploaded;
|
||||||
this.uri = config.media_folder && !uploaded ? config.media_folder + '/' + value : value;
|
this.uri = config.media_folder && !uploaded ? config.media_folder + '/' + value : value;
|
||||||
this.toString = function() {
|
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});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user