Sidebar updates

This commit is contained in:
Codex Agent
2026-03-08 19:27:44 +00:00
parent edb08e3e5c
commit 6a0347fd22

View File

@@ -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<string, UnitBucket>();
const calcs = getCalculatorsByCategory(key);
calcs.forEach(calc => {
[calc.labels.in1, calc.labels.in2].forEach(unit => {
const key = unit.toLowerCase();
const existing = buckets.get(key);
const unit = calc.labels.in1;
const bucketKey = unit.toLowerCase();
const existing = buckets.get(bucketKey);
if (existing) {
existing.conversions.push(calc);
} else {
buckets.set(key, {
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 };