only show extra charts if the player is being tracked
Some checks failed
Deploy / deploy (push) Has been cancelled

This commit is contained in:
Lee 2024-10-02 10:48:28 +01:00
parent 859df1dea3
commit 37ea0f4244
3 changed files with 45 additions and 28 deletions

@ -37,7 +37,7 @@ export default interface ScoreSaberPlayer extends Player {
/** /**
* The rank history for this player. * The rank history for this player.
*/ */
statisticHistory: { [date: string]: PlayerHistory }; statisticHistory: { [key: string]: PlayerHistory };
/** /**
* The statistics for this player. * The statistics for this player.
@ -58,6 +58,12 @@ export default interface ScoreSaberPlayer extends Player {
* Whether the player is inactive or not. * Whether the player is inactive or not.
*/ */
inactive: boolean; inactive: boolean;
/**
* Whether the player is having their
* statistics being tracked or not.
*/
isBeingTracked?: boolean;
} }
export async function getScoreSaberPlayerFromToken(token: ScoreSaberPlayerToken): Promise<ScoreSaberPlayer> { export async function getScoreSaberPlayerFromToken(token: ScoreSaberPlayerToken): Promise<ScoreSaberPlayer> {
@ -74,6 +80,7 @@ export async function getScoreSaberPlayerFromToken(token: ScoreSaberPlayerToken)
}; };
}) || []; }) || [];
let isBeingTracked = false;
const todayDate = formatDateMinimal(getMidnightAlignedDate(new Date())); const todayDate = formatDateMinimal(getMidnightAlignedDate(new Date()));
let statisticHistory: { [key: string]: PlayerHistory } = {}; let statisticHistory: { [key: string]: PlayerHistory } = {};
try { try {
@ -96,6 +103,8 @@ export async function getScoreSaberPlayerFromToken(token: ScoreSaberPlayerToken)
averageRankedAccuracy: token.scoreStats.averageRankedAccuracy, averageRankedAccuracy: token.scoreStats.averageRankedAccuracy,
}, },
}; };
isBeingTracked = true;
} }
statisticHistory = history; statisticHistory = history;
} catch (error) { } catch (error) {
@ -168,6 +177,7 @@ export async function getScoreSaberPlayerFromToken(token: ScoreSaberPlayerToken)
permissions: token.permissions, permissions: token.permissions,
banned: token.banned, banned: token.banned,
inactive: token.inactive, inactive: token.inactive,
isBeingTracked: isBeingTracked,
}; };
} }

@ -1,10 +1,10 @@
"use client"; "use client";
import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player"; import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player";
import PlayerAccuracyChart from "@/components/player/chart/player-accuracy-chart";
import PlayerRankingChart from "@/components/player/chart/player-ranking-chart"; import PlayerRankingChart from "@/components/player/chart/player-ranking-chart";
import { FC, useState } from "react"; import { FC, useState } from "react";
import Tooltip from "@/components/tooltip"; import Tooltip from "@/components/tooltip";
import PlayerAccuracyChart from "@/components/player/chart/player-accuracy-chart";
type PlayerChartsProps = { type PlayerChartsProps = {
/** /**
@ -37,12 +37,15 @@ export default function PlayerCharts({ player }: PlayerChartsProps) {
chart: PlayerRankingChart, chart: PlayerRankingChart,
label: "Ranking", label: "Ranking",
}, },
{ ];
if (player.isBeingTracked) {
charts.push({
index: 1, index: 1,
chart: PlayerAccuracyChart, chart: PlayerAccuracyChart,
label: "Accuracy", label: "Accuracy",
}, });
]; }
const [selectedChart, setSelectedChart] = useState<SelectedChart>(charts[0]); const [selectedChart, setSelectedChart] = useState<SelectedChart>(charts[0]);
return ( return (
@ -50,7 +53,8 @@ export default function PlayerCharts({ player }: PlayerChartsProps) {
{selectedChart.chart({ player })} {selectedChart.chart({ player })}
<div className="flex items-center justify-center gap-2"> <div className="flex items-center justify-center gap-2">
{charts.map(chart => { {charts.length > 1 &&
charts.map(chart => {
const isSelected = chart.index === selectedChart.index; const isSelected = chart.index === selectedChart.index;
return ( return (

@ -126,9 +126,12 @@ export default function PlayerScores({ initialScoreData, initialSearch, player,
/** /**
* Gets the URL to the page. * Gets the URL to the page.
*/ */
const getUrl = (page: number) => { const getUrl = useCallback(
(page: number) => {
return `/player/${player.id}/${pageState.sort}/${page}${isSearchActive ? `?search=${debouncedSearchTerm}` : ""}`; return `/player/${player.id}/${pageState.sort}/${page}${isSearchActive ? `?search=${debouncedSearchTerm}` : ""}`;
}; },
[debouncedSearchTerm, player.id, pageState.sort]
);
/** /**
* Handle updating the URL when the page number, * Handle updating the URL when the page number,
@ -137,7 +140,7 @@ export default function PlayerScores({ initialScoreData, initialSearch, player,
useEffect(() => { useEffect(() => {
const newUrl = getUrl(pageState.page); const newUrl = getUrl(pageState.page);
window.history.replaceState({ ...window.history.state, as: newUrl, url: newUrl }, "", newUrl); window.history.replaceState({ ...window.history.state, as: newUrl, url: newUrl }, "", newUrl);
}, [pageState, debouncedSearchTerm, player.id, isSearchActive, getUrl]); }, [pageState, debouncedSearchTerm, player.id, isSearchActive]);
/**k /**k
* Handle scrolling to the top of the * Handle scrolling to the top of the