p5.js-web-editor/client/modules/IDE/reducers/collections.js

29 lines
759 B
JavaScript
Raw Normal View History

import * as ActionTypes from '../../../constants';
const sketches = (state = [], action) => {
switch (action.type) {
case ActionTypes.SET_COLLECTIONS:
return action.collections;
2019-07-09 18:24:09 +02:00
2019-10-20 15:31:20 +02:00
case ActionTypes.DELETE_COLLECTION:
return state.filter(({ id }) => action.collectionId !== id);
2019-09-16 22:58:32 +02:00
// The API returns the complete new edited collection
// with any items added or removed
case ActionTypes.EDIT_COLLECTION:
2019-07-09 18:24:09 +02:00
case ActionTypes.ADD_TO_COLLECTION:
case ActionTypes.REMOVE_FROM_COLLECTION:
return state.map((collection) => {
if (collection.id === action.payload.id) {
return action.payload;
}
return collection;
});
default:
return state;
}
};
export default sketches;