From f18b6ee7545a39673e11e69a1bc71f6008478a6e 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 12:40:49 -0600 Subject: [PATCH] feat: radix table --- src/app/tools/ratings/page.tsx | 165 +++++++++++++-------------------- src/stitches.config.ts | 2 + 2 files changed, 65 insertions(+), 102 deletions(-) diff --git a/src/app/tools/ratings/page.tsx b/src/app/tools/ratings/page.tsx index a6ae8eb47..dc7d320e2 100644 --- a/src/app/tools/ratings/page.tsx +++ b/src/app/tools/ratings/page.tsx @@ -17,7 +17,6 @@ import { ChangeEvent, useEffect, useRef, useState } from 'react'; import { create } from 'zustand'; import { BlitzkriegRatingsLeaderboardEntry } from '../../../../scripts/buildRatingsLeaderboard'; import { RatingsInfo, RatingsPlayer } from '../../../commands/ratings'; -import * as Leaderboard from '../../../components/Leaderboard'; import PageWrapper from '../../../components/PageWrapper'; import { LEAGUES } from '../../../constants/leagues'; import { FIRST_ARCHIVED_RATINGS_SEASON } from '../../../constants/ratings'; @@ -36,6 +35,7 @@ import { import { getArchivedLatestSeasonNumber } from '../../../core/blitzkrieg/getArchivedLatestSeasonNumber'; import getArchivedRatingsInfo from '../../../core/blitzkrieg/getArchivedRatingsInfo'; import { getArchivedRatingsLeaderboard } from '../../../core/blitzkrieg/getArchivedRatingsLeaderboard'; +import { theme } from '../../../stitches.config'; import { PageTurner } from './components/PageTurner'; const ROWS_PER_PAGE = 30; @@ -490,38 +490,8 @@ 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 ( @@ -923,39 +893,6 @@ export default function Page() { - - - - Selected player - Position - Percentile - Score - - - - - - - {highlightedUsername} - {highlightedClan ? ` [${highlightedClan}]` : ''} - - - {highlightedPosition - ? (highlightedPosition + 1).toLocaleString() - : '--'} - {' / '} - {totalPlayers?.toLocaleString() ?? '--'} - - - {highlightedPercentile ? `Top ${highlightedPercentile}%` : '--'} - - - {highlightedScore?.toLocaleString() ?? '--'} - - - - - - - {players === null ? ( - - ) : ( - range( - page * ROWS_PER_PAGE, - Math.min( - page * ROWS_PER_PAGE + ROWS_PER_PAGE, - ratingsInfo?.detail ? 0 : (ratingsInfo?.count ?? 1) - 1, - ), - ).map((index) => { - const id = players[region][season]?.[index]?.id; + + + + Position + Player + + Percentile + + Score + + - return ( - { - setHighlightedPlayer({ type: 'position', position: index }); - }} - /> - ); - }) - )} - + {range( + page * ROWS_PER_PAGE, + Math.min( + page * ROWS_PER_PAGE + ROWS_PER_PAGE, + ratingsInfo?.detail ? 0 : (ratingsInfo?.count ?? 1) - 1, + ), + ).map((index) => { + const id = players[region][season]?.[index]?.id; + const clan = id ? names[region][id]?.clan : undefined; + const highlight = highlightedPlayer + ? highlightedPlayer.type === 'id' + ? highlightedPlayer.id === id + : highlightedPlayer.position === index + : false; + const row = ( + { + setHighlightedPlayer({ type: 'position', position: index }); + }} + > + + {(index + 1).toLocaleString()}. + + + {names[region][id] === null + ? `Deleted player ${id}` + : names[region][id]?.nickname ?? `Loading player...`} + {clan ? ` [${clan}]` : ''} + + + {totalPlayers + ? Math.ceil(((index + 1) / totalPlayers) * 100) + : '--'} + % + + + {players[region][season]?.[index]?.score.toLocaleString()} + + + ); + + return row; + })} +