mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
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.
This commit is contained in:
@@ -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 (
|
||||
<span className="col-lrow-avatar">
|
||||
<PlaceAvatar place={place} size={40} category={category} />
|
||||
|
||||
@@ -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 `<span class="trek-rating-badge" style="
|
||||
position:absolute;bottom:-4px;right:-4px;
|
||||
|
||||
Reference in New Issue
Block a user