static-cms/src/reducers/entryDraft.js

33 lines
873 B
JavaScript
Raw Normal View History

import { Map, List } from 'immutable';
2016-06-10 00:16:01 -03:00
import { DRAFT_CREATE, DRAFT_DISCARD, DRAFT_CHANGE } from '../actions/entries';
import { ADD_MEDIA } from '../actions/media';
const initialState = Map({entry: Map(), mediaFiles: List()});
2016-06-10 00:16:01 -03:00
const entryDraft = (state = Map(), action) => {
switch (action.type) {
case DRAFT_CREATE:
if (!action.payload) {
// New entry
return initialState;
}
// Existing Entry
return state.withMutations((state) => {
state.set('entry', action.payload);
state.set('mediaFiles', List());
});
case DRAFT_DISCARD:
return initialState;
case DRAFT_CHANGE:
return state.set('entry', action.payload);
2016-06-10 00:16:01 -03:00
case ADD_MEDIA:
return state.update('mediaFiles', (list) => list.push(action.payload.name));
default:
return state;
}
2016-06-10 00:16:01 -03:00
};
export default entryDraft;