Collapse stop groups by default on collection screen

Drivers see a flat list of stops (suppliers / area clusters / POs)
on first load and tap one to drill into its items. Previously every
group auto-expanded on load, which buried the day at a glance under
every item row.

- Remove the three setExpanded*(allIds) auto-expand calls in loadItems
- Empty Set() defaults keep state stable across refreshes and tab switches
- expandAll() toolbar action still available for bulk-open
- SupplierGroup / AreaGroup already render the collapsed preview line
  (first 3 items +N more) so the stop's contents stay visible without
  expanding
This commit is contained in:
Dave 2026-09-08 18:41:14 +02:00
parent 4efce9290c
commit 2e3ec03927

View file

@ -146,23 +146,15 @@ const loadItems = useCallback(async (showLoading = true) => {
setItems(data);
setFilteredItems(data);
setCached(statusFilter, data);
const allSupplierIds = new Set<string>();
data.forEach(i => {
if (i.expand?.supplier?.id) allSupplierIds.add(i.expand.supplier.id);
});
setExpandedSuppliers(allSupplierIds);
const allAreaIds = new Set<string>();
const clusters = clusterByProximity(data, 2);
clusters.forEach(c => allAreaIds.add(c.id));
setExpandedAreas(allAreaIds);
// Auto-expand every PO sub-group on first load — drivers want to
// see all of a PO's items at once. Per-PO collapse is opt-in.
const allPoIds = new Set<string>();
data.forEach(i => {
const po = i.expand?.purchase_order;
allPoIds.add(po?.id || '__no_po__');
});
setExpandedPOs(allPoIds);
// Default to ALL groups collapsed. Drivers see a flat list of
// stops (suppliers / area clusters / POs) on first load and tap
// one to drill into its items — matches the "open the app,
// see your day" mental model. The "Show all" toolbar action
// (`expandAll`) is still available for the rare case where a
// driver wants everything expanded at once.
setExpandedSuppliers(new Set());
setExpandedAreas(new Set());
setExpandedPOs(new Set());
} catch (err) {
console.error('Failed to load collections:', err);
setError('Failed to load collections. Pull down to retry.');