From 04dda00b7f24cde58458bc62391a71b91acbae08 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 28 Sep 2024 14:51:17 +0100 Subject: [PATCH] use type for tracked status --- src/app/(pages)/api/player/isbeingtracked/route.ts | 3 ++- src/common/player/player-tracked-since.ts | 11 +++++++++++ src/components/player/player-tracked-status.tsx | 10 +++++----- 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 src/common/player/player-tracked-since.ts diff --git a/src/app/(pages)/api/player/isbeingtracked/route.ts b/src/app/(pages)/api/player/isbeingtracked/route.ts index 9cb7591..8319238 100644 --- a/src/app/(pages)/api/player/isbeingtracked/route.ts +++ b/src/app/(pages)/api/player/isbeingtracked/route.ts @@ -1,6 +1,7 @@ import { NextRequest, NextResponse } from "next/server"; import { connectMongo } from "@/common/mongo"; import { IPlayer, PlayerModel } from "@/common/schema/player-schema"; +import { PlayerTrackedSince } from "@/common/player/player-tracked-since"; export async function GET(request: NextRequest) { const id = request.nextUrl.searchParams.get("id"); @@ -13,7 +14,7 @@ export async function GET(request: NextRequest) { await connectMongo(); // Connect to Mongo const foundPlayer: IPlayer | null = await PlayerModel.findById(id); - const response: { tracked: boolean; trackedSince?: string } = { + const response: PlayerTrackedSince = { tracked: foundPlayer != null, }; if (foundPlayer != null) { diff --git a/src/common/player/player-tracked-since.ts b/src/common/player/player-tracked-since.ts new file mode 100644 index 0000000..6841f65 --- /dev/null +++ b/src/common/player/player-tracked-since.ts @@ -0,0 +1,11 @@ +export interface PlayerTrackedSince { + /** + * Whether the player statistics are being tracked + */ + tracked: boolean; + + /** + * The date the player was first tracked + */ + trackedSince?: string; +} diff --git a/src/components/player/player-tracked-status.tsx b/src/components/player/player-tracked-status.tsx index 7d18808..7d611c4 100644 --- a/src/components/player/player-tracked-status.tsx +++ b/src/components/player/player-tracked-status.tsx @@ -7,6 +7,7 @@ import { config } from "../../../config"; import Tooltip from "@/components/tooltip"; import { InformationCircleIcon } from "@heroicons/react/16/solid"; import { format } from "@formkit/tempo"; +import { PlayerTrackedSince } from "@/common/player/player-tracked-since"; type Props = { player: ScoreSaberPlayer; @@ -17,10 +18,9 @@ export default function PlayerTrackedStatus({ player }: Props) { queryKey: ["playerIsBeingTracked", player.id], queryFn: () => ky - .get<{ - tracked: boolean; - trackedSince: string; - }>(`${config.siteUrl}/api/player/isbeingtracked?id=${player.id}`) + .get( + `${config.siteUrl}/api/player/isbeingtracked?id=${player.id}`, + ) .json(), }); @@ -34,7 +34,7 @@ export default function PlayerTrackedStatus({ player }: Props) { display={

This player is having their statistics tracked!

-

Tracked Since: {format(data.trackedSince)}

+

Tracked Since: {format(data.trackedSince!)}

} side="bottom"