- Added Done category in the grocery list and pushed it to the bottom

This commit is contained in:
Dejan
2024-12-08 13:38:27 +01:00
parent 12f1a51292
commit 47a0ea2f36

View File

@ -51,9 +51,12 @@ const GroceryList = ({onInputFocus}: {onInputFocus: (y: number) => void}) => {
const [choreDialogVisible, setChoreDialogVisible] = useState<boolean>(false); const [choreDialogVisible, setChoreDialogVisible] = useState<boolean>(false);
// Group approved groceries by category // Group approved groceries by category
const approvedGroceriesByCategory = approvedGroceries?.reduce( let approvedGroceriesByCategory = approvedGroceries?.reduce(
(groups: any, item: IGrocery) => { (groups: any, item: IGrocery) => {
const category = item.category || "Uncategorized"; let category = item.category || "Uncategorized";
if (item.bought) {
category = "Done";
}
if (!groups[category]) { if (!groups[category]) {
groups[category] = []; groups[category] = [];
} }
@ -261,7 +264,11 @@ const GroceryList = ({onInputFocus}: {onInputFocus: (y: number) => void}) => {
{approvedGroceries?.length > 0 {approvedGroceries?.length > 0
? approvedVisible && ( ? approvedVisible && (
<FlatList <FlatList
data={Object.keys(approvedGroceriesByCategory)} data={Object.keys(approvedGroceriesByCategory).sort((a, b) => {
if (a !== "Done") return -1;
if (b === "Done") return 1;
return 0;
})}
renderItem={({item: category}) => ( renderItem={({item: category}) => (
<View key={category}> <View key={category}>
{/* Render Category Header */} {/* Render Category Header */}