show no data if data is missing instead of showing 0
Some checks failed
Deploy Backend / deploy (push) Successful in 5m1s
Deploy Website / deploy (push) Has been cancelled

This commit is contained in:
Lee 2024-10-12 03:11:02 +01:00
parent 1d6647b74e
commit 7327b8d169
2 changed files with 13 additions and 9 deletions

@ -165,7 +165,7 @@ export async function getScoreSaberPlayerFromToken(
* @param daysAgo the amount of days ago to get the stat for
* @return the change
*/
const getChange = (statType: "rank" | "countryRank" | "pp", daysAgo: number = 1): number => {
const getChange = (statType: "rank" | "countryRank" | "pp", daysAgo: number = 1): number | undefined => {
const todayStats = statisticHistory[todayDate];
let otherDate: string | undefined;
@ -184,19 +184,19 @@ export async function getScoreSaberPlayerFromToken(
otherDate = formatDateMinimal(date);
}
if (!otherDate) {
return 0;
return undefined;
}
const otherStats = statisticHistory[otherDate];
const hasChange = !!(todayStats && otherStats);
if (!hasChange) {
return 0;
return undefined;
}
const statToday = todayStats[`${statType}`];
const statOther = otherStats[`${statType}`];
if (!statToday || !statOther) {
return 0;
return undefined;
}
return (statToday - statOther) * (statType == "pp" ? 1 : -1);

@ -48,20 +48,24 @@ const renderChange = (player: ScoreSaberPlayer, type: "rank" | "countryRank" | "
const monthlyStat = monthlyStats?.[type];
const renderChange = (value: number | undefined, timeFrame: "daily" | "weekly" | "monthly") => {
if (value == undefined) {
return "Missing Data";
}
const format = (value: number) => {
const format = (value: number | undefined) => {
if (value == 0) {
return 0;
}
if (value == undefined) {
return "No Data";
}
return type == "pp" ? formatPp(value) + "pp" : formatNumberWithCommas(value);
};
return (
<p>
{capitalizeFirstLetter(timeFrame)} Change:{" "}
<span className={`${value >= 0 ? (value == 0 ? "" : "text-green-500") : "text-red-500"}`}>{format(value)}</span>
<span
className={`${value == undefined ? "" : value >= 0 ? (value == 0 ? "" : "text-green-500") : "text-red-500"}`}
>
{format(value)}
</span>
</p>
);
};