From d8342e6dff35ce5a28b257c2f1290421aa855c91 Mon Sep 17 00:00:00 2001 From: beatz174-bit Date: Sun, 23 Nov 2025 16:50:46 +1000 Subject: [PATCH] Fix pick list product filtering --- src/screens/ActivePickListScreen.tsx | 35 +++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/screens/ActivePickListScreen.tsx b/src/screens/ActivePickListScreen.tsx index 18e1757..a572980 100644 --- a/src/screens/ActivePickListScreen.tsx +++ b/src/screens/ActivePickListScreen.tsx @@ -87,22 +87,45 @@ export const ActivePickListScreen = () => { }, [visibleItemsByStatus, productMap]); const sortedProducts = useMemo(() => { - const uniqueProducts = new Map(); + const dedupedById = new Map(); products.forEach((product) => { - const normalizedName = product.name.trim().toLowerCase(); - const existing = uniqueProducts.get(normalizedName); - + const existing = dedupedById.get(product.id); if (!existing || product.updated_at > existing.updated_at) { - uniqueProducts.set(normalizedName, product); + dedupedById.set(product.id, product); } }); - return Array.from(uniqueProducts.values()).sort((a, b) => + const dedupedByName = new Map(); + + dedupedById.forEach((product) => { + const normalizedName = product.name.trim().toLowerCase(); + const existing = dedupedByName.get(normalizedName); + + if (!existing || product.updated_at > existing.updated_at) { + dedupedByName.set(normalizedName, product); + } + }); + + return Array.from(dedupedByName.values()).sort((a, b) => a.name.localeCompare(b.name, undefined, { sensitivity: 'base' }), ); }, [products]); + const categoryFilteredProducts = useMemo(() => { + if (!pickList?.categories || pickList.categories.length === 0) { + return sortedProducts; + } + + const allowedCategories = new Set( + pickList.categories.map((category) => category.trim().toLowerCase()), + ); + + return sortedProducts.filter((product) => + allowedCategories.has(product.category.trim().toLowerCase()), + ); + }, [pickList?.categories, sortedProducts]); + const hasCartonItems = useMemo( () => visibleItemsByStatus.some((item) => item.is_carton), [visibleItemsByStatus],