From f2ef170f01381b69f5995b5dda75e6a333f270cb Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 15 Oct 2024 19:43:23 +0100 Subject: [PATCH] fix --- .../src/controller/image.controller.ts | 2 +- .../backend/src/service/image.service.tsx | 4 ++-- projects/common/src/utils/number-utils.ts | 20 +++++++++++++++++++ projects/website/src/common/number-utils.ts | 19 ------------------ .../src/components/input/search-player.tsx | 2 +- .../leaderboard/leaderboard-score-stats.tsx | 2 +- .../player/chart/player-ranking-chart.tsx | 2 +- .../src/components/player/player-header.tsx | 2 +- .../src/components/player/player-stats.tsx | 2 +- .../player/player-tracked-status.tsx | 2 +- .../website/src/components/ranking/mini.tsx | 2 +- .../src/components/ranking/player-ranking.tsx | 2 +- .../src/components/score/score-rank-info.tsx | 2 +- .../src/components/score/score-stats.tsx | 2 +- 14 files changed, 33 insertions(+), 32 deletions(-) delete mode 100644 projects/website/src/common/number-utils.ts diff --git a/projects/backend/src/controller/image.controller.ts b/projects/backend/src/controller/image.controller.ts index 0fa4dd7..8ed58c6 100644 --- a/projects/backend/src/controller/image.controller.ts +++ b/projects/backend/src/controller/image.controller.ts @@ -11,6 +11,6 @@ export default class ImageController { }), }) public async getOpenGraphImage({ params: { id } }: { params: { id: string } }) { - return await ImageService.generateOpenGraphImage(id); + return await ImageService.generatePlayerImage(id); } } diff --git a/projects/backend/src/service/image.service.tsx b/projects/backend/src/service/image.service.tsx index 7d9daa3..8331a81 100644 --- a/projects/backend/src/service/image.service.tsx +++ b/projects/backend/src/service/image.service.tsx @@ -1,7 +1,7 @@ import { ImageResponse } from "@vercel/og"; import { scoresaberService } from "@ssr/common/service/impl/scoresaber"; -import { formatNumberWithCommas, formatPp } from "website/src/common/number-utils"; import React from "react"; +import { formatNumberWithCommas, formatPp } from "@ssr/common/utils/number-utils"; export class ImageService { /** @@ -9,7 +9,7 @@ export class ImageService { * * @param id the player's id */ - public static async generateOpenGraphImage(id: string) { + public static async generatePlayerImage(id: string) { const player = await scoresaberService.lookupPlayer(id); if (player == undefined) { return undefined; diff --git a/projects/common/src/utils/number-utils.ts b/projects/common/src/utils/number-utils.ts index 64c81be..512694e 100644 --- a/projects/common/src/utils/number-utils.ts +++ b/projects/common/src/utils/number-utils.ts @@ -7,3 +7,23 @@ export function isWholeNumber(number: number) { return number % 1 === 0; } + +/** + * Formats a number without trailing zeros. + * + * @param num the number to format + * @returns the formatted number + */ +export function formatNumberWithCommas(num: number) { + return num.toLocaleString(); +} + +/** + * Formats the pp value + * + * @param num the pp to format + * @returns the formatted pp + */ +export function formatPp(num: number) { + return num.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 }); +} diff --git a/projects/website/src/common/number-utils.ts b/projects/website/src/common/number-utils.ts deleted file mode 100644 index 4974c9b..0000000 --- a/projects/website/src/common/number-utils.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Formats a number without trailing zeros. - * - * @param num the number to format - * @returns the formatted number - */ -export function formatNumberWithCommas(num: number) { - return num.toLocaleString(); -} - -/** - * Formats the pp value - * - * @param num the pp to format - * @returns the formatted pp - */ -export function formatPp(num: number) { - return num.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 }); -} diff --git a/projects/website/src/components/input/search-player.tsx b/projects/website/src/components/input/search-player.tsx index 34016f9..6af3817 100644 --- a/projects/website/src/components/input/search-player.tsx +++ b/projects/website/src/components/input/search-player.tsx @@ -1,6 +1,6 @@ "use client"; -import { formatNumberWithCommas } from "@/common/number-utils"; +import { formatNumberWithCommas } from "@ssr/common/utils/number-utils"; import { zodResolver } from "@hookform/resolvers/zod"; import Link from "next/link"; import { useState } from "react"; diff --git a/projects/website/src/components/leaderboard/leaderboard-score-stats.tsx b/projects/website/src/components/leaderboard/leaderboard-score-stats.tsx index 160280c..d394f1d 100644 --- a/projects/website/src/components/leaderboard/leaderboard-score-stats.tsx +++ b/projects/website/src/components/leaderboard/leaderboard-score-stats.tsx @@ -1,4 +1,4 @@ -import { formatNumberWithCommas } from "@/common/number-utils"; +import { formatNumberWithCommas } from "@ssr/common/utils/number-utils"; import { XMarkIcon } from "@heroicons/react/24/solid"; import clsx from "clsx"; import { getScoreBadgeFromAccuracy } from "@/common/song-utils"; diff --git a/projects/website/src/components/player/chart/player-ranking-chart.tsx b/projects/website/src/components/player/chart/player-ranking-chart.tsx index 048443f..5b5fbdf 100644 --- a/projects/website/src/components/player/chart/player-ranking-chart.tsx +++ b/projects/website/src/components/player/chart/player-ranking-chart.tsx @@ -1,6 +1,6 @@ "use client"; -import { formatNumberWithCommas } from "@/common/number-utils"; +import { formatNumberWithCommas } from "@ssr/common/utils/number-utils"; import React from "react"; import { DatasetConfig } from "@/components/chart/generic-chart"; import GenericPlayerChart from "@/components/player/chart/generic-player-chart"; diff --git a/projects/website/src/components/player/player-header.tsx b/projects/website/src/components/player/player-header.tsx index 2dc8137..1ad7e3b 100644 --- a/projects/website/src/components/player/player-header.tsx +++ b/projects/website/src/components/player/player-header.tsx @@ -1,4 +1,4 @@ -import { formatNumberWithCommas, formatPp } from "@/common/number-utils"; +import { formatNumberWithCommas, formatPp } from "@ssr/common/utils/number-utils"; import { GlobeAmericasIcon } from "@heroicons/react/24/solid"; import Card from "../card"; import CountryFlag from "../country-flag"; diff --git a/projects/website/src/components/player/player-stats.tsx b/projects/website/src/components/player/player-stats.tsx index 0cafe7f..e090807 100644 --- a/projects/website/src/components/player/player-stats.tsx +++ b/projects/website/src/components/player/player-stats.tsx @@ -1,4 +1,4 @@ -import { formatNumberWithCommas } from "@/common/number-utils"; +import { formatNumberWithCommas } from "@ssr/common/utils/number-utils"; import StatValue from "@/components/stat-value"; import ScoreSaberPlayer from "@ssr/common/types/player/impl/scoresaber-player"; diff --git a/projects/website/src/components/player/player-tracked-status.tsx b/projects/website/src/components/player/player-tracked-status.tsx index 3621fa8..1cba40c 100644 --- a/projects/website/src/components/player/player-tracked-status.tsx +++ b/projects/website/src/components/player/player-tracked-status.tsx @@ -5,7 +5,7 @@ import ky from "ky"; import { config } from "../../../config"; import Tooltip from "@/components/tooltip"; import { InformationCircleIcon } from "@heroicons/react/16/solid"; -import { formatNumberWithCommas } from "@/common/number-utils"; +import { formatNumberWithCommas } from "@ssr/common/utils/number-utils"; import { PlayerTrackedSince } from "@ssr/common/types/player/player-tracked-since"; import ScoreSaberPlayer from "@ssr/common/types/player/impl/scoresaber-player"; diff --git a/projects/website/src/components/ranking/mini.tsx b/projects/website/src/components/ranking/mini.tsx index 62c8f6b..c36e4c8 100644 --- a/projects/website/src/components/ranking/mini.tsx +++ b/projects/website/src/components/ranking/mini.tsx @@ -1,4 +1,4 @@ -import { formatNumberWithCommas, formatPp } from "@/common/number-utils"; +import { formatNumberWithCommas, formatPp } from "@ssr/common/utils/number-utils"; import { GlobeAmericasIcon } from "@heroicons/react/24/solid"; import { useQuery } from "@tanstack/react-query"; import Link from "next/link"; diff --git a/projects/website/src/components/ranking/player-ranking.tsx b/projects/website/src/components/ranking/player-ranking.tsx index b5448b5..5f54fcb 100644 --- a/projects/website/src/components/ranking/player-ranking.tsx +++ b/projects/website/src/components/ranking/player-ranking.tsx @@ -1,6 +1,6 @@ "use client"; -import { formatNumberWithCommas, formatPp } from "@/common/number-utils"; +import { formatNumberWithCommas, formatPp } from "@ssr/common/utils/number-utils"; import CountryFlag from "@/components/country-flag"; import ScoreSaberPlayerToken from "@ssr/common/types/token/scoresaber/score-saber-player-token"; import Link from "next/link"; diff --git a/projects/website/src/components/score/score-rank-info.tsx b/projects/website/src/components/score/score-rank-info.tsx index ce7a9dd..038374e 100644 --- a/projects/website/src/components/score/score-rank-info.tsx +++ b/projects/website/src/components/score/score-rank-info.tsx @@ -1,4 +1,4 @@ -import { formatNumberWithCommas } from "@/common/number-utils"; +import { formatNumberWithCommas } from "@ssr/common/utils/number-utils"; import { format } from "@formkit/tempo"; import { GlobeAmericasIcon } from "@heroicons/react/24/solid"; import Tooltip from "../tooltip"; diff --git a/projects/website/src/components/score/score-stats.tsx b/projects/website/src/components/score/score-stats.tsx index 0c04552..b2bbbe3 100644 --- a/projects/website/src/components/score/score-stats.tsx +++ b/projects/website/src/components/score/score-stats.tsx @@ -1,4 +1,4 @@ -import { formatNumberWithCommas, formatPp } from "@/common/number-utils"; +import { formatNumberWithCommas, formatPp } from "@ssr/common/utils/number-utils"; import { getScoreBadgeFromAccuracy } from "@/common/song-utils"; import { XMarkIcon } from "@heroicons/react/24/solid"; import clsx from "clsx";