From 04799fa44b86328b2a2cd238fe38d93b62fb1f10 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Fri, 1 Jan 2021 16:34:10 -0700 Subject: [PATCH] Fix checkboxes in NestsContainer.tsx --- .../scripts/components/admin/nests/NestsContainer.tsx | 4 ++-- resources/scripts/state/admin/nests.ts | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/resources/scripts/components/admin/nests/NestsContainer.tsx b/resources/scripts/components/admin/nests/NestsContainer.tsx index 9ae2f96c..d44f448c 100644 --- a/resources/scripts/components/admin/nests/NestsContainer.tsx +++ b/resources/scripts/components/admin/nests/NestsContainer.tsx @@ -23,9 +23,9 @@ const RowCheckbox = ({ id }: { id: number}) => { checked={isChecked} onChange={(e: React.ChangeEvent) => { if (e.currentTarget.checked) { - appendSelectedNest(name); + appendSelectedNest(id); } else { - removeSelectedNest(name); + removeSelectedNest(id); } }} /> diff --git a/resources/scripts/state/admin/nests.ts b/resources/scripts/state/admin/nests.ts index 3002c6d2..a0d817a1 100644 --- a/resources/scripts/state/admin/nests.ts +++ b/resources/scripts/state/admin/nests.ts @@ -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); }), };