Preserve pick list item ordering by creation time

This commit is contained in:
beatz174-bit
2025-11-24 15:56:36 +10:00
parent 69a01914bf
commit 66de93dc65
+8 -13
View File
@@ -78,25 +78,20 @@ export const ActivePickListScreen = () => {
const sortedItems = useMemo(() => { const sortedItems = useMemo(() => {
return [...itemsVisibleByStatus].sort((a, b) => { return [...itemsVisibleByStatus].sort((a, b) => {
const timeA = a.created_at ?? 0;
const timeB = b.created_at ?? 0;
if (timeA !== timeB) {
return timeA - timeB;
}
const productA = productMap.get(a.product_id); const productA = productMap.get(a.product_id);
const productB = productMap.get(b.product_id); const productB = productMap.get(b.product_id);
const nameA = productA?.name.trim().toLowerCase() ?? ''; const nameA = productA?.name.trim().toLowerCase() ?? '';
const nameB = productB?.name.trim().toLowerCase() ?? ''; const nameB = productB?.name.trim().toLowerCase() ?? '';
const nameComparison = nameA.localeCompare(nameB, undefined, { sensitivity: 'base' }); return nameA.localeCompare(nameB, undefined, { sensitivity: 'base' });
if (nameComparison !== 0) {
return nameComparison;
}
if (a.is_carton !== b.is_carton) {
return a.is_carton ? 1 : -1;
}
const timeA = a.updated_at ?? a.created_at;
const timeB = b.updated_at ?? b.created_at;
return timeA - timeB;
}); });
}, [itemsVisibleByStatus, productMap]); }, [itemsVisibleByStatus, productMap]);