Skip to content

Commit

Permalink
format score
Browse files Browse the repository at this point in the history
  • Loading branch information
marnym committed Nov 12, 2023
1 parent 38b3ae9 commit 485dd82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dance-app/src/components/Leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Loader from "./Loader";
import "../Leaderboard.css";
import { Card, CardContent, CardMedia, Stack, Typography } from "@mui/material";
import pb from "../pocketBase";
import { formatScore } from "../sections/MainScore";

interface VideoData {
id: string;
Expand Down Expand Up @@ -67,7 +68,7 @@ function Leaderboard() {
<Typography variant="body2">
{expand?.user?.name}
{": "}
<b>{score}</b>
<b>{formatScore(score)}</b>
</Typography>
</CardContent>
</Card>
Expand Down
10 changes: 9 additions & 1 deletion dance-app/src/sections/MainScore.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { Box, useTheme } from "@mui/material";
import Loader from "../components/Loader";

const formatter = Intl.NumberFormat("en", {
maximumFractionDigits: 2,
});

// eslint-disable-next-line
export const formatScore = (score?: number | null) =>
score ? formatter.format(score) : score;

const MainScore = ({
score,
subscribed,
Expand All @@ -16,7 +24,7 @@ const MainScore = ({
className="submit-container"
sx={{ fontSize: "4rem", color: theme.palette.success.main }}
>
{(!score || score === -1) && subscribed ? <Loader /> : score}
{subscribed && (!score || score === -1) ? <Loader /> : formatScore(score)}
</Box>
);
};
Expand Down

0 comments on commit 485dd82

Please sign in to comment.