From de08c6c5b161a37f5f37ff83f3684586cccf6fa9 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Wed, 5 Mar 2025 21:40:47 -0500 Subject: [PATCH] Enhance ChoresGrouper to include chore filters and update localStorage handling for selectedChoreFilter --- src/views/Chores/MyChores.jsx | 38 +++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/views/Chores/MyChores.jsx b/src/views/Chores/MyChores.jsx index 780d476..7373b25 100644 --- a/src/views/Chores/MyChores.jsx +++ b/src/views/Chores/MyChores.jsx @@ -139,7 +139,11 @@ const MyChores = () => { const sortedChores = choresData.res.sort(ChoreSorter) setChores(sortedChores) setFilteredChores(sortedChores) - const sections = ChoresGrouper(selectedChoreSection, sortedChores) + const sections = ChoresGrouper( + selectedChoreSection, + sortedChores, + ChoreFilters(userProfile)[selectedChoreFilter], + ) setChoreSections(sections) if (localStorage.getItem('openChoreSections') === null) { setSelectedChoreSectionWithCache(selectedChoreSection) @@ -178,7 +182,7 @@ const MyChores = () => { } const setSelectedChoreFilterWithCache = value => { setSelectedChoreFilter(value) - localStorage.setItem('selectedChoreFilter', JSON.stringify(value)) + localStorage.setItem('selectedChoreFilter', value) } const updateChores = newChore => { @@ -186,7 +190,13 @@ const MyChores = () => { newChores.push(newChore) setChores(newChores) setFilteredChores(newChores) - setChoreSections(ChoresGrouper(selectedChoreSection, newChores)) + setChoreSections( + ChoresGrouper( + selectedChoreSection, + newChores, + ChoreFilters(userProfile)[selectedChoreFilter], + ), + ) setSearchFilter('All') } const handleMenuOutsideClick = event => { @@ -262,7 +272,13 @@ const MyChores = () => { } setChores(newChores) setFilteredChores(newFilteredChores) - setChoreSections(ChoresGrouper(selectedChoreSection, newChores)) + setChoreSections( + ChoresGrouper( + selectedChoreSection, + newChores, + ChoreFilters(userProfile)[selectedChoreFilter], + ), + ) switch (event) { case 'completed': @@ -293,7 +309,13 @@ const MyChores = () => { ) setChores(newChores) setFilteredChores(newFilteredChores) - setChoreSections(ChoresGrouper(selectedChoreSection, newChores)) + setChoreSections( + ChoresGrouper( + selectedChoreSection, + newChores, + ChoreFilters(userProfile)[selectedChoreFilter], + ), + ) } const searchOptions = { @@ -449,7 +471,11 @@ const MyChores = () => { ) }} onItemSelect={selected => { - const section = ChoresGrouper(selected.value, chores) + const section = ChoresGrouper( + selected.value, + chores, + ChoreFilters(userProfile)[selectedChoreFilter], + ) setChoreSections(section) setSelectedChoreSectionWithCache(selected.value) setOpenChoreSectionsWithCache(