From 6a0347fd22378bc782cbb14c7abd84684adf8351 Mon Sep 17 00:00:00 2001 From: Codex Agent Date: Sun, 8 Mar 2026 19:27:44 +0000 Subject: [PATCH] Sidebar updates --- hdyc-svelte/src/lib/components/Sidebar.svelte | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/hdyc-svelte/src/lib/components/Sidebar.svelte b/hdyc-svelte/src/lib/components/Sidebar.svelte index 8cdb80b..1b0c0a3 100644 --- a/hdyc-svelte/src/lib/components/Sidebar.svelte +++ b/hdyc-svelte/src/lib/components/Sidebar.svelte @@ -31,42 +31,32 @@ conversions: CalculatorDef[]; }; - const sortConversionsForUnit = (conversions: CalculatorDef[], unitLabel: string) => { - const normalizedUnit = unitLabel.toLowerCase(); - return conversions.slice().sort((a, b) => { - const aIsSource = a.labels.in1?.toLowerCase() === normalizedUnit; - const bIsSource = b.labels.in1?.toLowerCase() === normalizedUnit; - if (aIsSource !== bIsSource) { - return aIsSource ? -1 : 1; - } - return a.name.localeCompare(b.name); - }); - }; + const sortConversionsForUnit = (conversions: CalculatorDef[]) => + conversions.slice().sort((a, b) => a.name.localeCompare(b.name)); $: categoryUnitGroups = Object.entries(categories).map(([key, meta]) => { const buckets = new Map(); const calcs = getCalculatorsByCategory(key); calcs.forEach(calc => { - [calc.labels.in1, calc.labels.in2].forEach(unit => { - const key = unit.toLowerCase(); - const existing = buckets.get(key); - if (existing) { - existing.conversions.push(calc); - } else { - buckets.set(key, { - label: unit, - conversions: [calc], - }); - } - }); + const unit = calc.labels.in1; + const bucketKey = unit.toLowerCase(); + const existing = buckets.get(bucketKey); + if (existing) { + existing.conversions.push(calc); + } else { + buckets.set(bucketKey, { + label: unit, + conversions: [calc], + }); + } }); const units = [...buckets.entries()] .sort(([a], [b]) => a.localeCompare(b)) .map(([, bucket]) => ({ label: bucket.label, - conversions: sortConversionsForUnit(bucket.conversions, bucket.label), + conversions: sortConversionsForUnit(bucket.conversions), })); return { key, meta, units };