Choices/assets/scripts/src/reducers/items.js

51 lines
1 KiB
JavaScript
Raw Normal View History

const items = (state = [], action) => {
switch (action.type) {
case 'ADD_ITEM': {
// Add object to items array
const newState = [...state, {
id: action.id,
choiceId: action.choiceId,
2016-10-18 20:23:07 +02:00
groupId: action.groupId,
value: action.value,
label: action.label,
active: true,
highlighted: false,
2017-07-19 19:48:46 +02:00
customProperties: action.customProperties,
keyCode: null
}];
return newState.map((item) => {
if (item.highlighted) {
item.highlighted = false;
2016-08-14 23:14:37 +02:00
}
return item;
});
}
case 'REMOVE_ITEM': {
// Set item to inactive
return state.map((item) => {
if (item.id === action.id) {
item.active = false;
2016-08-14 23:14:37 +02:00
}
return item;
});
}
case 'HIGHLIGHT_ITEM': {
return state.map((item) => {
if (item.id === action.id) {
item.highlighted = action.highlighted;
2016-08-14 23:14:37 +02:00
}
return item;
});
}
default: {
return state;
}
}
2016-08-14 23:14:37 +02:00
};
2016-09-24 12:07:48 +02:00
export default items;