2019-07-09 08:35:24 +00:00
|
|
|
import * as ActionTypes from '../../../constants';
|
|
|
|
|
|
|
|
const sketches = (state = [], action) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case ActionTypes.SET_COLLECTIONS:
|
|
|
|
return action.collections;
|
2019-07-09 16:24:09 +00:00
|
|
|
|
2019-09-16 20:58:32 +00:00
|
|
|
// The API returns the complete new edited collection
|
|
|
|
// with any items added or removed
|
|
|
|
case ActionTypes.EDIT_COLLECTION:
|
2019-07-09 16:24:09 +00: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;
|
|
|
|
});
|
2019-07-09 08:35:24 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default sketches;
|