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:
@@ -31,10 +31,14 @@
|
||||
let highlightedUnitId = $state<string | null>(null);
|
||||
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(() => {
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user