Compare commits

..

No commits in common. "b8553c313846a0ebd43877aa5acda4f7e854bae1" and "b5cfbf384aa858fc032c942fa83ce6150311ed90" have entirely different histories.

3 changed files with 14 additions and 11 deletions

@ -4,6 +4,9 @@ import { PlayerHistory } from "../player-history";
import ScoreSaberPlayerToken from "../../token/scoresaber/score-saber-player-token"; import ScoreSaberPlayerToken from "../../token/scoresaber/score-saber-player-token";
import { formatDateMinimal, getDaysAgoDate, getMidnightAlignedDate } from "../../../utils/time-utils"; import { formatDateMinimal, getDaysAgoDate, getMidnightAlignedDate } from "../../../utils/time-utils";
import { getPageFromRank } from "../../../utils/utils"; import { getPageFromRank } from "../../../utils/utils";
import { db } from "website/src/common/database/database";
import { isServer } from "@tanstack/react-query";
import { getCookieValue } from "../../../utils/cookie-utils";
/** /**
* A ScoreSaber player. * A ScoreSaber player.
@ -76,12 +79,10 @@ export default interface ScoreSaberPlayer extends Player {
* *
* @param token the player token * @param token the player token
* @param apiUrl the api url for SSR * @param apiUrl the api url for SSR
* @param playerIdCookie the id of the claimed player
*/ */
export async function getScoreSaberPlayerFromToken( export async function getScoreSaberPlayerFromToken(
token: ScoreSaberPlayerToken, token: ScoreSaberPlayerToken,
apiUrl: string, apiUrl: string
playerIdCookie?: string
): Promise<ScoreSaberPlayer> { ): Promise<ScoreSaberPlayer> {
const bio: ScoreSaberBio = { const bio: ScoreSaberBio = {
lines: token.bio?.split("\n") || [], lines: token.bio?.split("\n") || [],
@ -100,12 +101,13 @@ export async function getScoreSaberPlayerFromToken(
const todayDate = formatDateMinimal(getMidnightAlignedDate(new Date())); const todayDate = formatDateMinimal(getMidnightAlignedDate(new Date()));
let statisticHistory: { [key: string]: PlayerHistory } = {}; let statisticHistory: { [key: string]: PlayerHistory } = {};
const playerIdCookie = isServer ? await getCookieValue("playerId") : (await db.getSettings())?.playerId;
try { try {
const { statistics: history } = await ky const { statistics: history } = await ky
.get<{ .get<{
statistics: { [key: string]: PlayerHistory }; statistics: { [key: string]: PlayerHistory };
}>( }>(
`${apiUrl}/player/history/${token.id}${playerIdCookie && playerIdCookie == token.id ? "?createIfMissing=true" : ""}` `${apiUrl}/player/history/${token.id}${playerIdCookie && playerIdCookie === token.id ? "?createIfMissing=true" : ""}`
) )
.json(); .json();
if (history) { if (history) {

@ -55,8 +55,7 @@ const getPlayerData = async ({ params }: Props, fetchScores: boolean = true): Pr
} }
const playerToken = await scoresaberService.lookupPlayer(id); const playerToken = await scoresaberService.lookupPlayer(id);
const player = const player = playerToken && (await getScoreSaberPlayerFromToken(playerToken, config.siteApi));
playerToken && (await getScoreSaberPlayerFromToken(playerToken, config.siteApi, await getCookieValue("playerId")));
let scores: ScoreSaberPlayerScoresPageToken | undefined; let scores: ScoreSaberPlayerScoresPageToken | undefined;
if (fetchScores) { if (fetchScores) {
scores = await scoresaberService.lookupPlayerScores({ scores = await scoresaberService.lookupPlayerScores({

@ -49,7 +49,7 @@ export default function PlayerData({
if (playerResponse == undefined) { if (playerResponse == undefined) {
return undefined; return undefined;
} }
return await getScoreSaberPlayerFromToken(playerResponse, config.siteApi, settings?.playerId); return await getScoreSaberPlayerFromToken(playerResponse, config.siteApi);
}, },
refetchInterval: REFRESH_INTERVAL, refetchInterval: REFRESH_INTERVAL,
refetchIntervalInBackground: false, refetchIntervalInBackground: false,
@ -63,10 +63,12 @@ export default function PlayerData({
<div className="flex gap-2"> <div className="flex gap-2">
<article className="flex flex-col gap-2"> <article className="flex flex-col gap-2">
<PlayerHeader player={player} /> <PlayerHeader player={player} />
{!player.inactive && (
<Card className="gap-1"> <Card className="gap-1">
<PlayerBadges player={player} /> <PlayerBadges player={player} />
{!player.inactive && <PlayerCharts player={player} />} <PlayerCharts player={player} />
</Card> </Card>
)}
<PlayerScores <PlayerScores
initialScoreData={initialScoreData} initialScoreData={initialScoreData}
initialSearch={initialSearch} initialSearch={initialSearch}