Fix checkboxes in NestsContainer.tsx

This commit is contained in:
Matthew Penner 2021-01-01 16:34:10 -07:00
parent f72402b5fa
commit 04799fa44b
2 changed files with 4 additions and 8 deletions

View File

@ -23,9 +23,9 @@ const RowCheckbox = ({ id }: { id: number}) => {
checked={isChecked}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
if (e.currentTarget.checked) {
appendSelectedNest(name);
appendSelectedNest(id);
} else {
removeSelectedNest(name);
removeSelectedNest(id);
}
}}
/>

View File

@ -39,15 +39,11 @@ const nests: AdminNestStore = {
}),
appendSelectedNest: action((state, payload) => {
if (state.selectedNests.find(id => id === payload)) {
state.selectedNests = state.selectedNests.map(id => id === payload ? payload : id);
} else {
state.selectedNests = [ ...state.selectedNests, payload ];
}
state.selectedNests = state.selectedNests.filter(id => id !== payload).concat(payload);
}),
removeSelectedNest: action((state, payload) => {
state.selectedNests = [ ...state.selectedNests.filter(id => id !== payload) ];
state.selectedNests = state.selectedNests.filter(id => id !== payload);
}),
};