diff --git a/src/common/data-fetcher/data-fetcher.ts b/src/common/data-fetcher/data-fetcher.ts index 8728798..a136ef6 100644 --- a/src/common/data-fetcher/data-fetcher.ts +++ b/src/common/data-fetcher/data-fetcher.ts @@ -37,7 +37,7 @@ export default class DataFetcher { * @param url the url to fetch * @returns the fetched data */ - public async fetch(useProxy: boolean, url: string): Promise { + public async fetch(useProxy: boolean, url: string): Promise { try { return await ky .get(this.buildRequestUrl(useProxy, url), { @@ -47,8 +47,8 @@ export default class DataFetcher { }) .json(); } catch (error) { - console.error(error); - throw error; + console.error(`Error fetching data from ${url}:`, error); + return undefined; } } } diff --git a/src/common/data-fetcher/impl/scoresaber.ts b/src/common/data-fetcher/impl/scoresaber.ts index fc35a8e..ea0fc23 100644 --- a/src/common/data-fetcher/impl/scoresaber.ts +++ b/src/common/data-fetcher/impl/scoresaber.ts @@ -27,6 +27,9 @@ class ScoreSaberFetcher extends DataFetcher { useProxy, SEARCH_PLAYERS_ENDPOINT.replace(":query", query) ); + if (results === undefined) { + return undefined; + } if (results.players.length === 0) { return undefined; } diff --git a/src/common/scoresaber-utils.ts b/src/common/scoresaber-utils.ts new file mode 100644 index 0000000..01f41bc --- /dev/null +++ b/src/common/scoresaber-utils.ts @@ -0,0 +1,27 @@ +/** + * Formats the ScoreSaber difficulty number + * + * @param diff the diffuiclity number + */ +export function getDifficultyFromScoreSaberDifficulty(diff: number) { + switch (diff) { + case 1: { + return "Easy"; + } + case 3: { + return "Normal"; + } + case 5: { + return "Hard"; + } + case 7: { + return "Expert"; + } + case 9: { + return "Expert+"; + } + default: { + return "Unknown"; + } + } +} diff --git a/src/components/player/score/score.tsx b/src/components/player/score/score.tsx index cb3bc85..72d7852 100644 --- a/src/components/player/score/score.tsx +++ b/src/components/player/score/score.tsx @@ -4,11 +4,12 @@ import { copyToClipboard } from "@/common/browser-utils"; import { beatsaverFetcher } from "@/common/data-fetcher/impl/beatsaver"; import ScoreSaberPlayerScore from "@/common/data-fetcher/types/scoresaber/scoresaber-player-score"; import { formatNumberWithCommas } from "@/common/number-utils"; +import { getDifficultyFromScoreSaberDifficulty } from "@/common/scoresaber-utils"; import { songNameToYouTubeLink } from "@/common/song-utils"; import { timeAgo } from "@/common/time-utils"; import YouTubeLogo from "@/components/logos/youtube-logo"; import { useToast } from "@/hooks/use-toast"; -import { GlobeAmericasIcon } from "@heroicons/react/24/solid"; +import { GlobeAmericasIcon, StarIcon } from "@heroicons/react/24/solid"; import Image from "next/image"; import { useEffect, useState } from "react"; import BeatSaverLogo from "../../logos/beatsaver-logo"; @@ -43,14 +44,26 @@ export default function Score({ playerScore }: Props) {

{timeAgo(new Date(score.timeSet))}

- Song Artwork +
+
+ {leaderboard.stars > 0 ? ( +
+

{leaderboard.stars}

+ +
+ ) : ( +

{getDifficultyFromScoreSaberDifficulty(leaderboard.difficulty.difficulty)}

+ )} +
+ Song Artwork +

{leaderboard.songName}