1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-08-23 17:34:44 +02:00

Show rating on the discover page

This commit is contained in:
Kamran Ahmed
2024-08-26 21:19:59 +01:00
parent 6d58cb9a01
commit 9f14e83eb4
2 changed files with 12 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import { useState } from 'react';
import { cn } from '../../lib/classname';
import { decimalIfNeeded } from '../../lib/number.ts';
type RatingProps = {
rating?: number;
@@ -40,7 +41,7 @@ export function Rating(props: RatingProps) {
if (readOnly) {
return;
}
setStars(counter);
onRatingChange?.(counter);
}}
@@ -49,7 +50,12 @@ export function Rating(props: RatingProps) {
);
})}
{(props.total || 0) > 0 && (
<span className="ml-1.5 text-xs text-gray-400">
<span className="ml-1.5 text-xs font-medium text-gray-400">
{decimalIfNeeded(Number(props.rating!))}
</span>
)}
{(props.total || 0) > 0 && (
<span className="ml-1 text-xs text-gray-400">
({Intl.NumberFormat('en-US').format(props.total!)})
</span>
)}

View File

@@ -5,3 +5,7 @@ export const formatter = Intl.NumberFormat('en-US', {
export function formatCommaNumber(number: number): string {
return formatter.format(number);
}
export function decimalIfNeeded(number: number): string {
return number % 1 === 0 ? number.toString() : number.toFixed(1);
}