From 7327b8d16973e8e567e4b621aac785aa922b399a Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 12 Oct 2024 03:11:02 +0100 Subject: [PATCH] show no data if data is missing instead of showing 0 --- .../src/types/player/impl/scoresaber-player.ts | 8 ++++---- .../src/components/player/player-header.tsx | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/projects/common/src/types/player/impl/scoresaber-player.ts b/projects/common/src/types/player/impl/scoresaber-player.ts index 08c682a..7cefa13 100644 --- a/projects/common/src/types/player/impl/scoresaber-player.ts +++ b/projects/common/src/types/player/impl/scoresaber-player.ts @@ -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); diff --git a/projects/website/src/components/player/player-header.tsx b/projects/website/src/components/player/player-header.tsx index 50297a9..9d63e11 100644 --- a/projects/website/src/components/player/player-header.tsx +++ b/projects/website/src/components/player/player-header.tsx @@ -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 (

{capitalizeFirstLetter(timeFrame)} Change:{" "} - = 0 ? (value == 0 ? "" : "text-green-500") : "text-red-500"}`}>{format(value)} + = 0 ? (value == 0 ? "" : "text-green-500") : "text-red-500"}`} + > + {format(value)} +

); };