Skip to content

Commit a9cc01c

Browse files
omarKenawiVaiTon
authored andcommitted
fix(comparison): only show best/worst highlights when comparing multiple products
1 parent b8f0630 commit a9cc01c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/lib/ui/ComparisonDisplay.svelte

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,18 @@
197197
const bestValue = getBestValue(products, nutrientKey);
198198
const worstValue = getWorstValue(products, nutrientKey);
199199
200+
// Count how many products have this nutrient to avoid highlighting "best" when only one is compared
201+
const comparableCount = products
202+
.map((p) => getNutrientValue(p, nutrientKey))
203+
.filter((v): v is number => v !== null).length;
204+
200205
return {
201206
value,
202207
formatted,
203208
diff,
204209
diffFormatted,
205-
isBest: bestValue === value,
206-
isWorst: value === worstValue && products.length > 1
210+
isBest: comparableCount > 1 && bestValue === value,
211+
isWorst: comparableCount > 1 && worstValue === value
207212
};
208213
}
209214

0 commit comments

Comments
 (0)