Preparing for github file persistence
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
import { Map, List } from 'immutable';
|
||||
import { DRAFT_CREATE, DRAFT_DISCARD, DRAFT_CHANGE } from '../actions/entries';
|
||||
import { DRAFT_CREATE_FROM_ENTRY, DRAFT_DISCARD, DRAFT_CHANGE } from '../actions/entries';
|
||||
import { ADD_MEDIA, REMOVE_MEDIA } from '../actions/media';
|
||||
|
||||
const initialState = Map({ entry: Map(), mediaFiles: List() });
|
||||
|
||||
const entryDraft = (state = Map(), action) => {
|
||||
switch (action.type) {
|
||||
case DRAFT_CREATE:
|
||||
case DRAFT_CREATE_FROM_ENTRY:
|
||||
if (!action.payload) {
|
||||
// New entry
|
||||
return initialState;
|
||||
@ -14,6 +14,7 @@ const entryDraft = (state = Map(), action) => {
|
||||
// Existing Entry
|
||||
return state.withMutations((state) => {
|
||||
state.set('entry', action.payload);
|
||||
state.setIn(['entry', 'newRecord'], false);
|
||||
state.set('mediaFiles', List());
|
||||
});
|
||||
case DRAFT_DISCARD:
|
||||
@ -22,9 +23,9 @@ const entryDraft = (state = Map(), action) => {
|
||||
return state.set('entry', action.payload);
|
||||
|
||||
case ADD_MEDIA:
|
||||
return state.update('mediaFiles', (list) => list.push(action.payload.uri));
|
||||
return state.update('mediaFiles', (list) => list.push(action.payload.path));
|
||||
case REMOVE_MEDIA:
|
||||
return state.update('mediaFiles', (list) => list.filterNot((uri) => uri === action.payload));
|
||||
return state.update('mediaFiles', (list) => list.filterNot((path) => path === action.payload));
|
||||
|
||||
default:
|
||||
return state;
|
||||
|
@ -23,5 +23,5 @@ export const selectEntry = (state, collection, slug) =>
|
||||
export const selectEntries = (state, collection) =>
|
||||
fromEntries.selectEntries(state.entries, collection);
|
||||
|
||||
export const getMedia = (state, uri) =>
|
||||
fromMedias.getMedia(state.medias, uri);
|
||||
export const getMedia = (state, path) =>
|
||||
fromMedias.getMedia(state.medias, path);
|
||||
|
@ -6,12 +6,12 @@ import MediaProxy from '../valueObjects/MediaProxy';
|
||||
const medias = (state = Map(), action) => {
|
||||
switch (action.type) {
|
||||
case ADD_MEDIA:
|
||||
return state.set(action.payload.uri, action.payload);
|
||||
return state.set(action.payload.path, 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 state.map((media, path) => {
|
||||
if (action.payload.persistedMediaFiles.indexOf(path) > -1) media.uploaded = true;
|
||||
return media;
|
||||
});
|
||||
|
||||
@ -22,10 +22,10 @@ const medias = (state = Map(), action) => {
|
||||
|
||||
export default medias;
|
||||
|
||||
export const getMedia = (state, uri) => {
|
||||
if (state.has(uri)) {
|
||||
return state.get(uri);
|
||||
export const getMedia = (state, path) => {
|
||||
if (state.has(path)) {
|
||||
return state.get(path);
|
||||
} else {
|
||||
return new MediaProxy(uri, null, true);
|
||||
return new MediaProxy(path, null, true);
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user