interface: simplify edit reducer

This commit is contained in:
Logan Allen 2021-02-12 12:02:52 -06:00
parent 1c4baea62f
commit 144178165c

View File

@ -59,18 +59,16 @@ const edit = (json: ContactUpdate, state: S) => {
if (!field) {
return;
}
const contact = state.contacts?.[ship];
const value = data['edit-field'][field];
if(!contact) {
return;
}
if(field === 'add-group') {
contact.groups.push(value);
state.contacts[ship].groups.push(value);
} else if (field === 'remove-group') {
contact.groups = contact.groups.filter(g => g !== value);
state.contacts[ship].groups =
state.contacts[ship].groups.filter(g => g !== value);
} else {
contact[field] = value;
state.contacts[ship][field] = value;
}
}
};