From 501e4449ef6b58a054fd75609c486cfa527cb25c Mon Sep 17 00:00:00 2001 From: Maurice Date: Mon, 30 Nov 2026 12:34:50 +0100 Subject: [PATCH] refactor(places): one label for a rating badge The list rows and the map pins wrote the average with their own copy of the whole star or one decimal rule; both now read ratingBadge. --- client/src/components/Collections/CollectionList.tsx | 6 ++---- client/src/components/Map/ratingBadge.ts | 5 +++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/client/src/components/Collections/CollectionList.tsx b/client/src/components/Collections/CollectionList.tsx index e0317079d..6f68748d5 100644 --- a/client/src/components/Collections/CollectionList.tsx +++ b/client/src/components/Collections/CollectionList.tsx @@ -7,9 +7,7 @@ import StatusBadge from './StatusBadge' import EntryTagDots from './EntryTagDots' import { usePlaceReorder } from './usePlaceReorder' import CategoryBadge from './CategoryBadge' - -/** A vote average as the map's pins write it: a whole number bare, else one decimal. */ -const ratingLabel = (rating: number): string => (Number.isInteger(rating) ? String(rating) : rating.toFixed(1)) +import { ratingBadge } from './ratingLabel' interface CollectionListProps { @@ -50,7 +48,7 @@ function rowClass(on: boolean, canReorder: boolean, dragging: boolean, dropSide: */ function RowAvatar({ place, t }: { place: CollectionPlace; t: TranslationFn }) { const category = place.category ? { color: place.category.color ?? undefined, icon: place.category.icon ?? undefined } : null - const rating = typeof place.rating_avg === 'number' && place.rating_avg > 0 ? ratingLabel(place.rating_avg) : null + const rating = ratingBadge(place.rating_avg) return ( diff --git a/client/src/components/Map/ratingBadge.ts b/client/src/components/Map/ratingBadge.ts index c43396c99..62c88fadb 100644 --- a/client/src/components/Map/ratingBadge.ts +++ b/client/src/components/Map/ratingBadge.ts @@ -1,3 +1,4 @@ +import { ratingBadge } from '../Collections/ratingLabel'; import './ratingBadge.css'; /** @@ -12,8 +13,8 @@ import './ratingBadge.css'; * already the whole sentence. */ export function ratingBadgeHtml(rating: number | null | undefined): string { - if (typeof rating !== 'number' || !(rating > 0)) return ''; - const label = Number.isInteger(rating) ? String(rating) : rating.toFixed(1); + const label = ratingBadge(rating); + if (!label) return ''; // Its amber and white live in ratingBadge.css, beside the list's badge of the same look. return `