Compare commits

...

2 Commits

Author SHA1 Message Date
b8553c3138 fix building
All checks were successful
Deploy Backend / deploy (push) Successful in 3m32s
Deploy Website / deploy (push) Successful in 4m58s
2024-10-17 03:17:42 +01:00
f83492ffdc show badges for inactive players 2024-10-17 03:13:37 +01:00
3 changed files with 11 additions and 14 deletions

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

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

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