add relative pp to the mini rankings and handle mobile support better for mini rankings
All checks were successful
Deploy / deploy (push) Successful in 5m21s

This commit is contained in:
Lee 2024-09-30 13:21:31 +01:00
parent 442e52d22d
commit 38702da204
6 changed files with 39 additions and 18 deletions

@ -24,4 +24,4 @@ export default function GlobalError({
</body> </body>
</html> </html>
); );
} }

@ -1,9 +1,13 @@
import Player, {StatisticChange} from "../player"; import Player, { StatisticChange } from "../player";
import ScoreSaberPlayerToken from "@/common/model/token/scoresaber/score-saber-player-token"; import ScoreSaberPlayerToken from "@/common/model/token/scoresaber/score-saber-player-token";
import {PlayerHistory} from "@/common/player/player-history"; import { PlayerHistory } from "@/common/player/player-history";
import {config} from "../../../../../config"; import { config } from "../../../../../config";
import ky from "ky"; import ky from "ky";
import {formatDateMinimal, getDaysAgoDate, getMidnightAlignedDate,} from "@/common/time-utils"; import {
formatDateMinimal,
getDaysAgoDate,
getMidnightAlignedDate,
} from "@/common/time-utils";
/** /**
* A ScoreSaber player. * A ScoreSaber player.

@ -1,7 +1,7 @@
"use client"; "use client";
import {createContext, useEffect, useState} from "react"; import { createContext, useEffect, useState } from "react";
import Database, {db} from "../../common/database/database"; import Database, { db } from "../../common/database/database";
import FullscreenLoader from "./fullscreen-loader"; import FullscreenLoader from "./fullscreen-loader";
/** /**

@ -29,6 +29,7 @@ export default function PlayerData({
page, page,
}: Props) { }: Props) {
const isMobile = useIsMobile(); const isMobile = useIsMobile();
console.log("mobile", isMobile);
let player = initalPlayerData; let player = initalPlayerData;
const { data, isLoading, isError } = useQuery({ const { data, isLoading, isError } = useQuery({
@ -60,7 +61,7 @@ export default function PlayerData({
/> />
</article> </article>
{!isMobile && ( {!isMobile && (
<aside className="w-[550px] hidden 2xl:flex flex-col gap-2"> <aside className="w-[600px] hidden 2xl:flex flex-col gap-2">
<Mini type="Global" player={player} /> <Mini type="Global" player={player} />
<Mini type="Country" player={player} /> <Mini type="Country" player={player} />
</aside> </aside>

@ -105,7 +105,7 @@ export default function Mini({ type, player }: MiniProps) {
{icon} {icon}
<p>{type} Ranking</p> <p>{type} Ranking</p>
</div> </div>
<div className="flex flex-col"> <div className="flex flex-col text-sm">
{isLoading && <p className="text-gray-400">Loading...</p>} {isLoading && <p className="text-gray-400">Loading...</p>}
{isError && <p className="text-red-500">Error</p>} {isError && <p className="text-red-500">Error</p>}
{players?.map((playerRanking, index) => { {players?.map((playerRanking, index) => {
@ -115,15 +115,16 @@ export default function Mini({ type, player }: MiniProps) {
playerRanking.name.length > PLAYER_NAME_MAX_LENGTH playerRanking.name.length > PLAYER_NAME_MAX_LENGTH
? playerRanking.name.substring(0, PLAYER_NAME_MAX_LENGTH) + "..." ? playerRanking.name.substring(0, PLAYER_NAME_MAX_LENGTH) + "..."
: playerRanking.name; : playerRanking.name;
const ppDifference = playerRanking.pp - player.pp;
return ( return (
<Link <Link
key={index} key={index}
href={`/player/${playerRanking.id}`} href={`/player/${playerRanking.id}`}
className="flex justify-between gap-2 bg-accent px-2 py-1.5 cursor-pointer transform-gpu transition-all hover:brightness-75 first:rounded-t last:rounded-b" className="grid gap-2 grid-cols-[auto_1fr_auto] items-center bg-accent px-2 py-1.5 cursor-pointer transform-gpu transition-all hover:brightness-75 first:rounded-t last:rounded-b"
> >
<div className="flex gap-2"> <p className="text-gray-400">#{formatNumberWithCommas(rank)}</p>
<p className="text-gray-400">#{formatNumberWithCommas(rank)}</p> <div className="flex gap-1 items-center">
<Avatar className="w-6 h-6 pointer-events-none"> <Avatar className="w-6 h-6 pointer-events-none">
<AvatarImage <AvatarImage
alt="Profile Picture" alt="Profile Picture"
@ -138,7 +139,19 @@ export default function Mini({ type, player }: MiniProps) {
{playerName} {playerName}
</p> </p>
</div> </div>
<p className="text-pp">{formatPp(playerRanking.pp)}pp</p> <div className="inline-flex min-w-[10.75em] gap-1 items-center">
<p className="text-pp text-right">
{formatPp(playerRanking.pp)}pp
</p>
{playerRanking.id !== player.id && (
<p
className={`text-xs text-right ${ppDifference > 0 ? "text-green-400" : "text-red-400"}`}
>
{ppDifference > 0 ? "+" : ""}
{formatPp(ppDifference)}
</p>
)}
</div>
</Link> </Link>
); );
})} })}

@ -1,16 +1,19 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
export function useIsMobile() { export function useIsMobile() {
const [isMobile, setIsMobile] = useState(false); const checkMobile = () => {
return window.innerWidth < 1536;
};
const [isMobile, setIsMobile] = useState(checkMobile());
useEffect(() => { useEffect(() => {
const handleResize = () => { const handleResize = () => {
setIsMobile(window.innerWidth < 768); setIsMobile(checkMobile());
}; };
window.addEventListener("resize", handleResize); window.addEventListener("resize", handleResize);
handleResize(); return () => {
window.removeEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize); };
}, []); }, []);
return isMobile; return isMobile;