From deb9e463e1c9147f7eb4b7fbd16e3437c3bc5011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Tue, 14 Nov 2023 11:24:38 -0600 Subject: [PATCH] feat: highlighted player stats --- src/app/tools/ratings/page.tsx | 70 +++++++++++++++++++ .../Leaderboard/components/Item.tsx | 1 + 2 files changed, 71 insertions(+) diff --git a/src/app/tools/ratings/page.tsx b/src/app/tools/ratings/page.tsx index 60bc17e71..a6ae8eb47 100644 --- a/src/app/tools/ratings/page.tsx +++ b/src/app/tools/ratings/page.tsx @@ -7,6 +7,7 @@ import { Dialog, Flex, Select, + Table, Text, TextField, } from '@radix-ui/themes'; @@ -489,6 +490,39 @@ export default function Page() { } } + const highlightedId = highlightedPlayer + ? highlightedPlayer.type === 'id' + ? highlightedPlayer.id + : players[region][season][highlightedPlayer.position]?.id + : undefined; + const highlightedUsername = + (highlightedPlayer && highlightedId + ? names[region][highlightedId]?.nickname + : undefined) ?? '--'; + const highlightedClan = + highlightedPlayer && highlightedId + ? names[region][highlightedId]?.clan + : undefined; + const highlightedPosition = highlightedPlayer + ? highlightedPlayer.type === 'position' + ? highlightedPlayer.position + : (() => { + const stringId = Object.entries(players[region][season]).find( + ([, player]) => player.id === highlightedId, + )?.[0]; + return stringId === undefined ? undefined : parseInt(stringId); + })() + : undefined; + const totalPlayers = + !ratingsInfo?.detail && ratingsInfo?.count ? ratingsInfo.count : undefined; + const highlightedPercentile = + highlightedPosition && totalPlayers + ? Math.ceil((highlightedPosition / totalPlayers) * 100) + : undefined; + const highlightedScore = highlightedPosition + ? players[region][season][highlightedPosition]?.score + : undefined; + return ( @@ -889,6 +923,39 @@ export default function Page() { + + + + Selected player + Position + Percentile + Score + + + + + + + {highlightedUsername} + {highlightedClan ? ` [${highlightedClan}]` : ''} + + + {highlightedPosition + ? (highlightedPosition + 1).toLocaleString() + : '--'} + {' / '} + {totalPlayers?.toLocaleString() ?? '--'} + + + {highlightedPercentile ? `Top ${highlightedPercentile}%` : '--'} + + + {highlightedScore?.toLocaleString() ?? '--'} + + + + + { + setHighlightedPlayer({ type: 'position', position: index }); + }} /> ); }) diff --git a/src/components/Leaderboard/components/Item.tsx b/src/components/Leaderboard/components/Item.tsx index e9554c48b..79a707ebe 100644 --- a/src/components/Leaderboard/components/Item.tsx +++ b/src/components/Leaderboard/components/Item.tsx @@ -32,6 +32,7 @@ export function Item({