2017-10-08 16:52:54 +02:00
|
|
|
export const defaultState = [];
|
|
|
|
|
|
|
|
export default function items(state = defaultState, action) {
|
2016-09-05 23:04:15 +02:00
|
|
|
switch (action.type) {
|
|
|
|
case 'ADD_ITEM': {
|
|
|
|
// Add object to items array
|
2018-05-28 14:55:44 +02:00
|
|
|
const newState = [
|
|
|
|
...state,
|
|
|
|
{
|
|
|
|
id: action.id,
|
|
|
|
choiceId: action.choiceId,
|
|
|
|
groupId: action.groupId,
|
|
|
|
value: action.value,
|
|
|
|
label: action.label,
|
|
|
|
active: true,
|
|
|
|
highlighted: false,
|
|
|
|
customProperties: action.customProperties,
|
|
|
|
placeholder: action.placeholder || false,
|
|
|
|
keyCode: null,
|
|
|
|
},
|
|
|
|
];
|
2016-04-12 15:10:07 +02:00
|
|
|
|
2018-05-28 14:55:44 +02:00
|
|
|
return newState.map(obj => {
|
2017-08-15 10:29:42 +02:00
|
|
|
const item = obj;
|
2017-12-10 19:00:57 +01:00
|
|
|
item.highlighted = false;
|
2019-10-29 19:26:11 +01:00
|
|
|
|
2016-09-05 23:04:15 +02:00
|
|
|
return item;
|
|
|
|
});
|
|
|
|
}
|
2016-04-12 15:10:07 +02:00
|
|
|
|
2016-09-05 23:04:15 +02:00
|
|
|
case 'REMOVE_ITEM': {
|
|
|
|
// Set item to inactive
|
2018-05-28 14:55:44 +02:00
|
|
|
return state.map(obj => {
|
2017-08-15 10:29:42 +02:00
|
|
|
const item = obj;
|
2016-09-05 23:04:15 +02:00
|
|
|
if (item.id === action.id) {
|
|
|
|
item.active = false;
|
2016-08-14 23:14:37 +02:00
|
|
|
}
|
2019-10-29 19:26:11 +01:00
|
|
|
|
2016-09-05 23:04:15 +02:00
|
|
|
return item;
|
|
|
|
});
|
|
|
|
}
|
2016-04-12 15:10:07 +02:00
|
|
|
|
2016-09-05 23:04:15 +02:00
|
|
|
case 'HIGHLIGHT_ITEM': {
|
2018-05-28 14:55:44 +02:00
|
|
|
return state.map(obj => {
|
2017-08-15 10:29:42 +02:00
|
|
|
const item = obj;
|
2016-09-05 23:04:15 +02:00
|
|
|
if (item.id === action.id) {
|
|
|
|
item.highlighted = action.highlighted;
|
2016-08-14 23:14:37 +02:00
|
|
|
}
|
2019-10-29 19:26:11 +01:00
|
|
|
|
2016-09-05 23:04:15 +02:00
|
|
|
return item;
|
|
|
|
});
|
|
|
|
}
|
2016-04-12 15:10:07 +02:00
|
|
|
|
2016-09-05 23:04:15 +02:00
|
|
|
default: {
|
|
|
|
return state;
|
2016-04-12 15:10:07 +02:00
|
|
|
}
|
2016-09-05 23:04:15 +02:00
|
|
|
}
|
2017-10-08 16:52:54 +02:00
|
|
|
}
|