feat: radix table

This commit is contained in:
TrèsAbhi committed 2023-11-14 12:40:49 -06:00
1 parent deb9e463e1
commit f18b6ee754
2 files changed
+65 -102

No files matched your search

+63 -102
View File
@@ -17,7 +17,6 @@ import { ChangeEvent, useEffect, useRef, useState } from 'react';
import { create } from 'zustand'; import { create } from 'zustand';
import { BlitzkriegRatingsLeaderboardEntry } from '../../../../scripts/buildRatingsLeaderboard'; import { BlitzkriegRatingsLeaderboardEntry } from '../../../../scripts/buildRatingsLeaderboard';
import { RatingsInfo, RatingsPlayer } from '../../../commands/ratings'; import { RatingsInfo, RatingsPlayer } from '../../../commands/ratings';
import * as Leaderboard from '../../../components/Leaderboard';
import PageWrapper from '../../../components/PageWrapper'; import PageWrapper from '../../../components/PageWrapper';
import { LEAGUES } from '../../../constants/leagues'; import { LEAGUES } from '../../../constants/leagues';
import { FIRST_ARCHIVED_RATINGS_SEASON } from '../../../constants/ratings'; import { FIRST_ARCHIVED_RATINGS_SEASON } from '../../../constants/ratings';
@@ -36,6 +35,7 @@ import {
import { getArchivedLatestSeasonNumber } from '../../../core/blitzkrieg/getArchivedLatestSeasonNumber'; import { getArchivedLatestSeasonNumber } from '../../../core/blitzkrieg/getArchivedLatestSeasonNumber';
import getArchivedRatingsInfo from '../../../core/blitzkrieg/getArchivedRatingsInfo'; import getArchivedRatingsInfo from '../../../core/blitzkrieg/getArchivedRatingsInfo';
import { getArchivedRatingsLeaderboard } from '../../../core/blitzkrieg/getArchivedRatingsLeaderboard'; import { getArchivedRatingsLeaderboard } from '../../../core/blitzkrieg/getArchivedRatingsLeaderboard';
import { theme } from '../../../stitches.config';
import { PageTurner } from './components/PageTurner'; import { PageTurner } from './components/PageTurner';
const ROWS_PER_PAGE = 30; 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 = const totalPlayers =
!ratingsInfo?.detail && ratingsInfo?.count ? ratingsInfo.count : undefined; !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 ( return (
<PageWrapper color="orange"> <PageWrapper color="orange">
@@ -923,39 +893,6 @@ export default function Page() {
</Flex> </Flex>
</Flex> </Flex>
<Table.Root variant="surface">
<Table.Header>
<Table.Row>
<Table.ColumnHeaderCell>Selected player</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>Position</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>Percentile</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>Score</Table.ColumnHeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>
{highlightedUsername}
{highlightedClan ? ` [${highlightedClan}]` : ''}
</Table.Cell>
<Table.Cell>
{highlightedPosition
? (highlightedPosition + 1).toLocaleString()
: '--'}
{' / '}
{totalPlayers?.toLocaleString() ?? '--'}
</Table.Cell>
<Table.Cell>
{highlightedPercentile ? `Top ${highlightedPercentile}%` : '--'}
</Table.Cell>
<Table.Cell>
{highlightedScore?.toLocaleString() ?? '--'}
</Table.Cell>
</Table.Row>
</Table.Body>
</Table.Root>
<PageTurner <PageTurner
page={page} page={page}
pages={pages} pages={pages}
@@ -964,45 +901,69 @@ export default function Page() {
} }
/> />
<Leaderboard.Root> <Table.Root variant="surface">
{players === null ? ( <Table.Header>
<Leaderboard.Gap message="Loading players..." /> <Table.Row>
) : ( <Table.ColumnHeaderCell width="0">Position</Table.ColumnHeaderCell>
range( <Table.ColumnHeaderCell>Player</Table.ColumnHeaderCell>
page * ROWS_PER_PAGE, <Table.ColumnHeaderCell width="0">
Math.min( Percentile
page * ROWS_PER_PAGE + ROWS_PER_PAGE, </Table.ColumnHeaderCell>
ratingsInfo?.detail ? 0 : (ratingsInfo?.count ?? 1) - 1, <Table.ColumnHeaderCell width="0">Score</Table.ColumnHeaderCell>
), </Table.Row>
).map((index) => { </Table.Header>
const id = players[region][season]?.[index]?.id;
return ( {range(
<Leaderboard.Item page * ROWS_PER_PAGE,
nickname={ Math.min(
names[region][id] === null page * ROWS_PER_PAGE + ROWS_PER_PAGE,
? `Deleted player ${id}` ratingsInfo?.detail ? 0 : (ratingsInfo?.count ?? 1) - 1,
: names[region][id]?.nickname ?? `Loading player...` ),
} ).map((index) => {
position={index + 1} const id = players[region][season]?.[index]?.id;
score={players[region][season]?.[index]?.score} const clan = id ? names[region][id]?.clan : undefined;
clan={id ? names[region][id]?.clan : undefined} const highlight = highlightedPlayer
key={index} ? highlightedPlayer.type === 'id'
highlight={ ? highlightedPlayer.id === id
highlightedPlayer : highlightedPlayer.position === index
? highlightedPlayer.type === 'id' : false;
? highlightedPlayer.id === id const row = (
: highlightedPlayer.position === index <Table.Row
: undefined style={{
} backgroundColor: highlight
onClick={() => { ? theme.colors.componentInteractiveActive_orange
setHighlightedPlayer({ type: 'position', position: index }); : 'unset',
}} cursor: 'pointer',
/> }}
); key={index}
}) onClick={() => {
)} setHighlightedPlayer({ type: 'position', position: index });
</Leaderboard.Root> }}
>
<Table.Cell key={index}>
{(index + 1).toLocaleString()}.
</Table.Cell>
<Table.Cell key={index}>
{names[region][id] === null
? `Deleted player ${id}`
: names[region][id]?.nickname ?? `Loading player...`}
<Text color="gray">{clan ? ` [${clan}]` : ''}</Text>
</Table.Cell>
<Table.Cell key={index} align="right">
{totalPlayers
? Math.ceil(((index + 1) / totalPlayers) * 100)
: '--'}
%
</Table.Cell>
<Table.Cell key={index} align="right">
{players[region][season]?.[index]?.score.toLocaleString()}
</Table.Cell>
</Table.Row>
);
return row;
})}
</Table.Root>
<PageTurner <PageTurner
page={page} page={page}
+2
View File
@@ -1,6 +1,7 @@
import { import {
amberDark, amberDark,
blueDark, blueDark,
orangeDark,
slate, slate,
slateDark, slateDark,
tealDark, tealDark,
@@ -16,6 +17,7 @@ export const theme = {
...createColors(slate, 'light'), ...createColors(slate, 'light'),
...createColors(amberDark, 'amber'), ...createColors(amberDark, 'amber'),
...createColors(orangeDark, 'orange'),
...createColors(blueDark, 'blue'), ...createColors(blueDark, 'blue'),
...createColors(tealDark, 'teal'), ...createColors(tealDark, 'teal'),
}, },