feat: initialize selected unit to base unit of first group on load

On initial page load (before any user interaction), the converter now
selects the base unit of the first visible group instead of the first
unit in the alphabetical list. Falls back to units[0] if the group's
baseUnitId is not found in the visible unit list. URL param ?from=
override and shift+click behavior are unaffected.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Falkan
2026-03-20 11:41:29 -04:00
parent 231eacc27c
commit 4d2d7c77d3

View File

@@ -31,10 +31,14 @@
let highlightedUnitId = $state<string | null>(null); let highlightedUnitId = $state<string | null>(null);
let yoloMode = $state<boolean>(false); let yoloMode = $state<boolean>(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(() => { $effect(() => {
if (fromUnitId === '' && units.length > 0) { 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;
} }
}); });