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;
|
||||
|
Reference in New Issue
Block a user