cleanup
Some checks failed
Deploy Website / deploy (push) Has been cancelled

This commit is contained in:
Lee 2024-10-11 19:58:49 +01:00
parent d7a3b734ec
commit ad87365a66

@ -10,6 +10,7 @@ import { ReactElement } from "react";
import PlayerTrackedStatus from "@/components/player/player-tracked-status"; import PlayerTrackedStatus from "@/components/player/player-tracked-status";
import ScoreSaberPlayer from "@ssr/common/types/player/impl/scoresaber-player"; import ScoreSaberPlayer from "@ssr/common/types/player/impl/scoresaber-player";
import Link from "next/link"; import Link from "next/link";
import { capitalizeFirstLetter } from "@/common/string-utils";
/** /**
* Renders the change for a stat. * Renders the change for a stat.
@ -42,15 +43,37 @@ const renderChange = (player: ScoreSaberPlayer, type: "rank" | "countryRank" | "
const todayStats = player.statisticChange?.today; const todayStats = player.statisticChange?.today;
const weeklyStats = player.statisticChange?.weekly; const weeklyStats = player.statisticChange?.weekly;
const monthlyStats = player.statisticChange?.monthly; const monthlyStats = player.statisticChange?.monthly;
const todayStat = todayStats?.[type];
const weeklyStat = weeklyStats?.[type];
const monthlyStat = monthlyStats?.[type];
const renderChange = (value: number | undefined, timeFrame: "daily" | "weekly" | "monthly") => {
if (value == undefined) {
return "Missing Data";
}
const format = (value: number) => {
if (value == 0) {
return 0;
}
return type == "pp" ? formatPp(value) : formatNumberWithCommas(value);
};
return (
<p>
{capitalizeFirstLetter(timeFrame)} Change:{" "}
<span className={`${value >= 0 ? (value == 0 ? "" : "text-green-500") : "text-red-500"}`}>{format(value)}</span>
</p>
);
};
return ( return (
<Tooltip <Tooltip
side="bottom" side="bottom"
display={ display={
<div> <div>
<p>Daily Change: {todayStats?.[type] || "Missing Data"}</p> {renderChange(todayStat, "daily")}
<p>Weekly Change: {weeklyStats?.[type] || "Missing Data"}</p> {renderChange(weeklyStat, "weekly")}
<p>Monthly Change: {monthlyStats?.[type] || "Missing Data"}</p> {renderChange(monthlyStat, "monthly")}
</div> </div>
} }
> >