Sort pick list product search options alphabetically

This commit is contained in:
beatz174-bit
2025-11-23 14:58:07 +10:00
parent 2f7d5024e8
commit 8782d61718
2 changed files with 46 additions and 3 deletions
+11 -3
View File
@@ -48,15 +48,23 @@ export const ActivePickListScreen = () => {
[areas, pickList?.area_id],
);
const sortedProducts = useMemo(
() =>
[...products].sort((a, b) =>
a.name.localeCompare(b.name, undefined, { sensitivity: 'base' }),
),
[products],
);
const filteredProducts = useMemo(() => {
const normalizedQuery = query.trim().toLowerCase();
if (!normalizedQuery) return products;
if (!normalizedQuery) return sortedProducts;
return products.filter((product) => {
return sortedProducts.filter((product) => {
const searchableText = `${product.name} ${product.category} ${product.barcode ?? ''}`.toLowerCase();
return searchableText.includes(normalizedQuery);
});
}, [products, query]);
}, [sortedProducts, query]);
useEffect(() => {
if (!selectedProduct) return;