2016-04-12 15:10:07 +02:00
|
|
|
const items = (state = [], action) => {
|
|
|
|
switch (action.type) {
|
2016-08-14 23:14:37 +02:00
|
|
|
case 'ADD_ITEM': {
|
2016-04-12 15:10:07 +02:00
|
|
|
// Add object to items array
|
2016-08-14 23:14:37 +02:00
|
|
|
const newState = [...state, {
|
2016-04-14 15:43:36 +02:00
|
|
|
id: action.id,
|
2016-06-27 15:46:12 +02:00
|
|
|
choiceId: action.choiceId,
|
2016-04-12 15:10:07 +02:00
|
|
|
value: action.value,
|
2016-04-16 18:06:27 +02:00
|
|
|
label: action.label,
|
2016-04-12 15:10:07 +02:00
|
|
|
active: true,
|
2016-08-14 23:14:37 +02:00
|
|
|
highlighted: false,
|
2016-04-12 15:10:07 +02:00
|
|
|
}];
|
|
|
|
|
|
|
|
return newState.map((item) => {
|
2016-08-14 23:14:37 +02:00
|
|
|
if (item.highlighted) {
|
2016-06-30 14:57:56 +02:00
|
|
|
item.highlighted = false;
|
2016-04-12 15:10:07 +02:00
|
|
|
}
|
|
|
|
return item;
|
|
|
|
});
|
2016-08-14 23:14:37 +02:00
|
|
|
}
|
2016-04-12 15:10:07 +02:00
|
|
|
|
2016-08-14 23:14:37 +02:00
|
|
|
case 'REMOVE_ITEM': {
|
2016-04-12 15:10:07 +02:00
|
|
|
// Set item to inactive
|
|
|
|
return state.map((item) => {
|
2016-08-14 23:14:37 +02:00
|
|
|
if (item.id === action.id) {
|
2016-04-12 15:10:07 +02:00
|
|
|
item.active = false;
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
});
|
2016-08-14 23:14:37 +02:00
|
|
|
}
|
2016-04-12 15:10:07 +02:00
|
|
|
|
2016-08-14 23:14:37 +02:00
|
|
|
case 'HIGHLIGHT_ITEM': {
|
2016-04-12 15:10:07 +02:00
|
|
|
return state.map((item) => {
|
2016-08-14 23:14:37 +02:00
|
|
|
if (item.id === action.id) {
|
2016-06-30 14:57:56 +02:00
|
|
|
item.highlighted = action.highlighted;
|
2016-04-12 15:10:07 +02:00
|
|
|
}
|
|
|
|
return item;
|
|
|
|
});
|
2016-08-14 23:14:37 +02:00
|
|
|
}
|
2016-04-12 15:10:07 +02:00
|
|
|
|
2016-08-14 23:14:37 +02:00
|
|
|
default: {
|
2016-04-12 15:10:07 +02:00
|
|
|
return state;
|
2016-08-14 23:14:37 +02:00
|
|
|
}
|
2016-04-12 15:10:07 +02:00
|
|
|
}
|
2016-08-14 23:14:37 +02:00
|
|
|
};
|
2016-04-12 15:10:07 +02:00
|
|
|
|
|
|
|
export default items;
|