From 65ad2147ab24b33e7a6868ae4c817fe402dc73bc Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 12 Sep 2024 00:35:54 +0100 Subject: [PATCH] add tooltip and diff colors --- src/common/song-utils.ts | 34 ++++++++++----------- src/common/youtube-utils.ts | 22 ++++++++++++++ src/components/player/score/score.tsx | 44 ++++++++++++++++++++------- 3 files changed, 72 insertions(+), 28 deletions(-) create mode 100644 src/common/youtube-utils.ts diff --git a/src/common/song-utils.ts b/src/common/song-utils.ts index 3c5203c..7909628 100644 --- a/src/common/song-utils.ts +++ b/src/common/song-utils.ts @@ -1,22 +1,22 @@ /** - * Turns a song name and author into a YouTube link + * Turns the difficulty of a song into a color * - * @param name the name of the song - * @param songSubName the sub name of the song - * @param author the author of the song - * @returns the YouTube link for the song + * @param diff the difficulty to get the color for + * @returns the color for the difficulty */ -export function songNameToYouTubeLink(name: string, songSubName: string, author: string) { - const baseUrl = "https://www.youtube.com/results?search_query="; - let query = ""; - if (name) { - query += `${name} `; +export function songDifficultyToColor(diff: string) { + switch (diff.toLowerCase()) { + case "easy": + return "#3cb371"; + case "normal": + return "#59b0f4"; + case "hard": + return "#FF6347"; + case "expert": + return "#bf2a42"; + case "expert+": + return "#8f48db"; + default: + return "gray"; } - if (songSubName) { - query += `${songSubName} `; - } - if (author) { - query += `${author} `; - } - return encodeURI(baseUrl + query.trim().replaceAll(" ", "+")); } diff --git a/src/common/youtube-utils.ts b/src/common/youtube-utils.ts new file mode 100644 index 0000000..3c5203c --- /dev/null +++ b/src/common/youtube-utils.ts @@ -0,0 +1,22 @@ +/** + * Turns a song name and author into a YouTube link + * + * @param name the name of the song + * @param songSubName the sub name of the song + * @param author the author of the song + * @returns the YouTube link for the song + */ +export function songNameToYouTubeLink(name: string, songSubName: string, author: string) { + const baseUrl = "https://www.youtube.com/results?search_query="; + let query = ""; + if (name) { + query += `${name} `; + } + if (songSubName) { + query += `${songSubName} `; + } + if (author) { + query += `${author} `; + } + return encodeURI(baseUrl + query.trim().replaceAll(" ", "+")); +} diff --git a/src/components/player/score/score.tsx b/src/components/player/score/score.tsx index 72d7852..cc90ced 100644 --- a/src/components/player/score/score.tsx +++ b/src/components/player/score/score.tsx @@ -5,9 +5,11 @@ 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 { songDifficultyToColor } from "@/common/song-utils"; import { timeAgo } from "@/common/time-utils"; +import { songNameToYouTubeLink } from "@/common/youtube-utils"; import YouTubeLogo from "@/components/logos/youtube-logo"; +import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { useToast } from "@/hooks/use-toast"; import { GlobeAmericasIcon, StarIcon } from "@heroicons/react/24/solid"; import Image from "next/image"; @@ -34,6 +36,8 @@ export default function Score({ playerScore }: Props) { })(); }, [playerScore, leaderboard.songHash]); + const diff = getDifficultyFromScoreSaberDifficulty(leaderboard.difficulty.difficulty); + return (
@@ -45,16 +49,34 @@ export default function Score({ playerScore }: Props) {
-
- {leaderboard.stars > 0 ? ( -
-

{leaderboard.stars}

- -
- ) : ( -

{getDifficultyFromScoreSaberDifficulty(leaderboard.difficulty.difficulty)}

- )} -
+ + + {leaderboard.stars > 0 ? ( +
+

{leaderboard.stars}

+ +
+ ) : ( +

{diff}

+ )} +
+ +

+ Difficulty: {diff} +

+ {leaderboard.stars > 0 && ( +

+ Stars: {leaderboard.stars} +

+ )} +
+