From 47a0ea2f3694a67cbbae4f38b7f1331d56fe2c9f Mon Sep 17 00:00:00 2001 From: Dejan Date: Sun, 8 Dec 2024 13:38:27 +0100 Subject: [PATCH] - Added Done category in the grocery list and pushed it to the bottom --- components/pages/grocery/GroceryList.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/components/pages/grocery/GroceryList.tsx b/components/pages/grocery/GroceryList.tsx index eb27677..e471df3 100644 --- a/components/pages/grocery/GroceryList.tsx +++ b/components/pages/grocery/GroceryList.tsx @@ -51,9 +51,12 @@ const GroceryList = ({onInputFocus}: {onInputFocus: (y: number) => void}) => { const [choreDialogVisible, setChoreDialogVisible] = useState(false); // Group approved groceries by category - const approvedGroceriesByCategory = approvedGroceries?.reduce( + let approvedGroceriesByCategory = approvedGroceries?.reduce( (groups: any, item: IGrocery) => { - const category = item.category || "Uncategorized"; + let category = item.category || "Uncategorized"; + if (item.bought) { + category = "Done"; + } if (!groups[category]) { groups[category] = []; } @@ -261,7 +264,11 @@ const GroceryList = ({onInputFocus}: {onInputFocus: (y: number) => void}) => { {approvedGroceries?.length > 0 ? approvedVisible && ( { + if (a !== "Done") return -1; + if (b === "Done") return 1; + return 0; + })} renderItem={({item: category}) => ( {/* Render Category Header */}