diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 0909715..96c1550 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -31,10 +31,14 @@ let highlightedUnitId = $state(null); let yoloMode = $state(false); - // Initialize fromUnitId to first unit once data arrives + // Initialize fromUnitId to the base unit of the first visible group. + // Falls back to units[0] if no groups or the base unit isn't in the visible list. $effect(() => { if (fromUnitId === '' && units.length > 0) { - fromUnitId = units[0].id; + const firstGroupBaseId = groups.length > 0 ? groups[0].baseUnitId : null; + fromUnitId = (firstGroupBaseId && units.some((u) => u.id === firstGroupBaseId)) + ? firstGroupBaseId + : units[0].id; } });