import { ScoresaberPlayer } from "@/schemas/scoresaber/player"; import { usePlayerScoresStore } from "@/store/playerScoresStore"; import { useSettingsStore } from "@/store/settingsStore"; import { formatNumber } from "@/utils/number"; import { calcPpBoundary, getHighestPpPlay } from "@/utils/scoresaber/scores"; import { GlobeAsiaAustraliaIcon, HomeIcon } from "@heroicons/react/20/solid"; import { useRef } from "react"; import ReactCountryFlag from "react-country-flag"; import { toast } from "react-toastify"; import { useStore } from "zustand"; import Avatar from "./Avatar"; import Card from "./Card"; import Label from "./Label"; import PlayerChart from "./PlayerChart"; type PlayerInfoProps = { playerData: ScoresaberPlayer; }; export default function PlayerInfo({ playerData }: PlayerInfoProps) { const playerId = playerData.id; const settingsStore = useStore(useSettingsStore, (store) => store); const playerScoreStore = useStore(usePlayerScoresStore, (store) => store); // Whether we have scores for this player in the local database const hasLocalScores = playerScoreStore?.exists(playerId); const toastId: any = useRef(null); async function claimProfile() { settingsStore?.setUserId(playerId); settingsStore?.refreshProfile(); const reponse = await playerScoreStore?.addPlayer( playerId, (page, totalPages) => { const autoClose = page == totalPages ? 5000 : false; if (page == 1) { toastId.current = toast.info( `Fetching scores ${page}/${totalPages}`, { autoClose: autoClose, progress: page / totalPages, }, ); } else { toast.update(toastId.current, { progress: page / totalPages, render: `Fetching scores ${page}/${totalPages}`, autoClose: autoClose, }); } console.log(`Fetching scores for ${playerId} (${page}/${totalPages})`); }, ); if (reponse?.error) { toast.error("Failed to claim profile"); console.log(reponse.message); return; } toast.success("Successfully claimed profile"); } return ( {/* Player Info */}
{/* Avatar */}
{/* Settings Buttons */}
{settingsStore?.userId !== playerId && ( )}
{/* Name */}

{playerData.name}

{/* Global Rank */}

#{playerData.rank}

{/* Country Rank */}

#{playerData.countryRank}

{/* PP */}

{formatNumber(playerData.pp)}pp

{/* Labels */}
{/* Chart */}
); }