From 6f4471777fbfde25160be0dd2f019790a3ad17d5 Mon Sep 17 00:00:00 2001 From: Nicolay Bennett Rennemo Date: Sun, 22 Nov 2026 21:12:47 +0100 Subject: [PATCH 1/2] Improved price sorting --- apps/frontend/src/components/VenuePrices.tsx | 18 ++++++ .../components/__tests__/VenuePrices.test.tsx | 58 +++++++++++++++++++ .../components/prices/ReportPriceDialog.tsx | 2 +- 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/apps/frontend/src/components/VenuePrices.tsx b/apps/frontend/src/components/VenuePrices.tsx index d7c36c2..d87c0ab 100644 --- a/apps/frontend/src/components/VenuePrices.tsx +++ b/apps/frontend/src/components/VenuePrices.tsx @@ -4,17 +4,35 @@ import { formatPrice, formatPriceLimitation } from '#/lib/format-price' import { useUserTimeZone } from '#/lib/use-user-time-zone' import type { VenuePriceSighting } from '#/types/venue' +const SIZE_VOLUME_ML: Record = { + PINT: 568, + HALF_LITER: 500, + QUARTER_LITER: 250, + CAN: 440, + OTHER: 0, +} + function isLimited(sighting: VenuePriceSighting) { return sighting.Limitations.length > 0 } +function volumeMl(sighting: VenuePriceSighting) { + return sighting.sizeMl ?? SIZE_VOLUME_ML[sighting.size] ?? 0 +} + function sortPrices(prices: VenuePriceSighting[]) { return [...prices].sort((a, b) => { + const volumeDiff = volumeMl(b) - volumeMl(a) + if (volumeDiff !== 0) return volumeDiff + const aLimited = isLimited(a) const bLimited = isLimited(b) if (aLimited !== bLimited) return aLimited ? 1 : -1 + const priceDiff = a.price - b.price + if (priceDiff !== 0) return priceDiff + return b.timeSighted.localeCompare(a.timeSighted) }) } diff --git a/apps/frontend/src/components/__tests__/VenuePrices.test.tsx b/apps/frontend/src/components/__tests__/VenuePrices.test.tsx index b6ca84b..9313d4d 100644 --- a/apps/frontend/src/components/__tests__/VenuePrices.test.tsx +++ b/apps/frontend/src/components/__tests__/VenuePrices.test.tsx @@ -44,6 +44,64 @@ describe('VenuePrices', () => { expect(screen.getByText('Happy hour 15:00–17:00')).toBeInTheDocument() }) + it('sorts by volume, then regular before limited, then price', () => { + render( + , + ) + + const rows = screen.getAllByRole('listitem').map((li) => li.textContent) + + expect(rows[0]).toContain('NOK 89 · pint') + expect(rows[1]).toContain('NOK 65 · pint') + expect(rows[2]).toContain('NOK 75 · pint') + expect(rows[3]).toContain('NOK 60 · half liter') + expect(rows[4]).toContain('NOK 55 · can') + expect(rows[5]).toContain('NOK 45 · 330 ml') + expect(rows[6]).toContain('NOK 35 · quarter liter') + }) + it('shows an empty state when no prices exist', () => { render() diff --git a/apps/frontend/src/components/prices/ReportPriceDialog.tsx b/apps/frontend/src/components/prices/ReportPriceDialog.tsx index 4bf6f5b..e4490d9 100644 --- a/apps/frontend/src/components/prices/ReportPriceDialog.tsx +++ b/apps/frontend/src/components/prices/ReportPriceDialog.tsx @@ -48,7 +48,7 @@ export function ReportPriceDialog({ trigger={ From ce7148a46b72ec2b7a26cc981d9db6dc04d20cb7 Mon Sep 17 00:00:00 2001 From: Nicolay Bennett Rennemo Date: Sun, 22 Nov 2026 21:24:08 +0100 Subject: [PATCH 2/2] lint --- apps/frontend/src/components/VenuePrices.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/frontend/src/components/VenuePrices.tsx b/apps/frontend/src/components/VenuePrices.tsx index d87c0ab..57c70ca 100644 --- a/apps/frontend/src/components/VenuePrices.tsx +++ b/apps/frontend/src/components/VenuePrices.tsx @@ -4,7 +4,7 @@ import { formatPrice, formatPriceLimitation } from '#/lib/format-price' import { useUserTimeZone } from '#/lib/use-user-time-zone' import type { VenuePriceSighting } from '#/types/venue' -const SIZE_VOLUME_ML: Record = { +const SIZE_VOLUME_ML: Partial> = { PINT: 568, HALF_LITER: 500, QUARTER_LITER: 250,