This commit is contained in:
parent
dda873b2fe
commit
8b935145f6
@ -23,6 +23,11 @@ export default interface ScoreSaberPlayer extends Player {
|
|||||||
*/
|
*/
|
||||||
pp: number;
|
pp: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The amount of pp gained compared to yesterday.
|
||||||
|
*/
|
||||||
|
ppGain: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The role the player has.
|
* The role the player has.
|
||||||
*/
|
*/
|
||||||
@ -75,6 +80,7 @@ export async function getScoreSaberPlayerFromToken(
|
|||||||
};
|
};
|
||||||
}) || [];
|
}) || [];
|
||||||
|
|
||||||
|
const todayDate = formatDateMinimal(getMidnightAlignedDate(new Date()));
|
||||||
let statisticHistory: { [key: string]: PlayerHistory } = {};
|
let statisticHistory: { [key: string]: PlayerHistory } = {};
|
||||||
try {
|
try {
|
||||||
const history = await ky
|
const history = await ky
|
||||||
@ -88,7 +94,7 @@ export async function getScoreSaberPlayerFromToken(
|
|||||||
}
|
}
|
||||||
if (history) {
|
if (history) {
|
||||||
// Use the latest data for today
|
// Use the latest data for today
|
||||||
history[formatDateMinimal(getMidnightAlignedDate(new Date()))] = {
|
history[todayDate] = {
|
||||||
rank: token.rank,
|
rank: token.rank,
|
||||||
countryRank: token.countryRank,
|
countryRank: token.countryRank,
|
||||||
pp: token.pp,
|
pp: token.pp,
|
||||||
@ -118,6 +124,12 @@ export async function getScoreSaberPlayerFromToken(
|
|||||||
.sort()
|
.sort()
|
||||||
.reduce((obj, [key, value]) => ({ ...obj, [key]: value }), {});
|
.reduce((obj, [key, value]) => ({ ...obj, [key]: value }), {});
|
||||||
}
|
}
|
||||||
|
const yesterdayDate = formatDateMinimal(
|
||||||
|
getMidnightAlignedDate(getDaysAgoDate(1)),
|
||||||
|
);
|
||||||
|
const ppGain =
|
||||||
|
(statisticHistory[yesterdayDate]?.pp || 0) -
|
||||||
|
(statisticHistory[todayDate]?.pp || 0);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: token.id,
|
id: token.id,
|
||||||
@ -129,6 +141,7 @@ export async function getScoreSaberPlayerFromToken(
|
|||||||
joinedDate: new Date(token.firstSeen),
|
joinedDate: new Date(token.firstSeen),
|
||||||
bio: bio,
|
bio: bio,
|
||||||
pp: token.pp,
|
pp: token.pp,
|
||||||
|
ppGain: ppGain < 0 ? 0 : ppGain,
|
||||||
role: role,
|
role: role,
|
||||||
badges: badges,
|
badges: badges,
|
||||||
statisticHistory: statisticHistory,
|
statisticHistory: statisticHistory,
|
||||||
|
@ -6,6 +6,7 @@ import { Avatar, AvatarImage } from "../ui/avatar";
|
|||||||
import ClaimProfile from "./claim-profile";
|
import ClaimProfile from "./claim-profile";
|
||||||
import PlayerStats from "./player-stats";
|
import PlayerStats from "./player-stats";
|
||||||
import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player";
|
import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player";
|
||||||
|
import Tooltip from "@/components/tooltip";
|
||||||
|
|
||||||
const playerData = [
|
const playerData = [
|
||||||
{
|
{
|
||||||
@ -29,7 +30,16 @@ const playerData = [
|
|||||||
{
|
{
|
||||||
showWhenInactiveOrBanned: true,
|
showWhenInactiveOrBanned: true,
|
||||||
render: (player: ScoreSaberPlayer) => {
|
render: (player: ScoreSaberPlayer) => {
|
||||||
return <p className="text-pp">{formatPp(player.pp)}pp</p>;
|
return (
|
||||||
|
<div className="text-pp flex gap-1 items-center">
|
||||||
|
<p>{formatPp(player.pp)}pp</p>
|
||||||
|
{player.ppGain > 0 && (
|
||||||
|
<Tooltip display={<p>The amount of PP you have gained today</p>}>
|
||||||
|
<span className="text-green-400 text-sm">+{player.ppGain}pp</span>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
Reference in New Issue
Block a user