2023-10-29 13:40:32 -05:00
|
|
|
'use client';
|
|
|
|
|
|
2023-11-02 11:14:13 -05:00
|
|
|
import {
|
|
|
|
|
CaretLeftIcon,
|
|
|
|
|
CaretRightIcon,
|
|
|
|
|
MagnifyingGlassIcon,
|
|
|
|
|
} from '@radix-ui/react-icons';
|
2023-11-07 11:02:11 -06:00
|
|
|
import { Button, Dialog, Flex, Select, TextField } from '@radix-ui/themes';
|
2023-10-31 15:20:37 -05:00
|
|
|
import { produce } from 'immer';
|
2023-11-07 11:50:51 -06:00
|
|
|
import { debounce, findLastIndex, range } from 'lodash';
|
2023-11-07 10:32:01 -06:00
|
|
|
import { ChangeEvent, useEffect, useRef, useState } from 'react';
|
2023-10-31 13:15:28 -05:00
|
|
|
import useSWR from 'swr';
|
2023-10-31 15:20:37 -05:00
|
|
|
import { create } from 'zustand';
|
2023-10-31 13:30:47 -05:00
|
|
|
import * as Leaderboard from '../../../components/Leaderboard';
|
2023-10-29 13:40:32 -05:00
|
|
|
import PageWrapper from '../../../components/PageWrapper';
|
2023-11-07 11:02:11 -06:00
|
|
|
import { LEAGUES } from '../../../constants/leagues';
|
2023-11-01 11:27:41 -05:00
|
|
|
import { FIRST_ARCHIVED_RATINGS_SEASON } from '../../../constants/ratings';
|
2023-10-30 21:57:22 -05:00
|
|
|
import { REGIONS, REGION_NAMES, Region } from '../../../constants/regions';
|
2023-11-07 10:32:01 -06:00
|
|
|
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
|
|
|
|
import fetchBlitz from '../../../core/blitz/fetchBlitz';
|
2023-10-31 15:20:37 -05:00
|
|
|
import { getAccountInfo } from '../../../core/blitz/getAccountInfo';
|
2023-10-31 15:31:03 -05:00
|
|
|
import { getClanAccountInfo } from '../../../core/blitz/getClanAccountInfo';
|
2023-10-31 12:35:32 -05:00
|
|
|
import getRatingsInfo from '../../../core/blitz/getRatingsInfo';
|
2023-11-07 10:32:01 -06:00
|
|
|
import { AccountList } from '../../../core/blitz/searchPlayersAcrossRegions';
|
2023-11-07 11:36:08 -06:00
|
|
|
import getArchivedRatingsInfo from '../../../core/blitzkrieg/getArchivedRatingsInfo';
|
|
|
|
|
import { getArchivedRatingsLeaderboard } from '../../../core/blitzkrieg/getArchivedRatingsLeaderboard';
|
2023-10-31 13:15:28 -05:00
|
|
|
import { numberFetcher } from '../../../core/blitzkrieg/numberFetcher';
|
2023-10-31 15:20:37 -05:00
|
|
|
import { noArrows } from './page.css';
|
2023-10-29 13:40:32 -05:00
|
|
|
|
2023-11-02 11:14:13 -05:00
|
|
|
const ROWS_OPTIONS = [5, 10, 25, 50, 100];
|
2023-10-31 15:20:37 -05:00
|
|
|
|
2023-11-07 11:13:30 -06:00
|
|
|
type UsernameCache = Record<Region, Record<number, string | null>>;
|
|
|
|
|
|
|
|
|
|
const useUsernameCache = create<UsernameCache>(() => ({
|
2023-10-31 15:20:37 -05:00
|
|
|
asia: {},
|
|
|
|
|
com: {},
|
|
|
|
|
eu: {},
|
|
|
|
|
}));
|
2023-10-31 15:31:03 -05:00
|
|
|
const useClanCache = create<Record<Region, Record<number, string | undefined>>>(
|
|
|
|
|
() => ({
|
|
|
|
|
asia: {},
|
|
|
|
|
com: {},
|
|
|
|
|
eu: {},
|
|
|
|
|
}),
|
|
|
|
|
);
|
2023-10-31 13:15:28 -05:00
|
|
|
|
2023-10-29 13:40:32 -05:00
|
|
|
export default function Page() {
|
2023-11-02 11:14:13 -05:00
|
|
|
const [rowsPerPage, setRowsPerPage] = useState(ROWS_OPTIONS[2]);
|
2023-10-31 15:20:37 -05:00
|
|
|
const usernameCache = useUsernameCache();
|
2023-10-31 15:31:03 -05:00
|
|
|
const clanCache = useClanCache();
|
2023-10-31 15:20:37 -05:00
|
|
|
const [region, setRegion] = useState<Region>('com');
|
2023-10-30 21:57:22 -05:00
|
|
|
// null being the latest season
|
|
|
|
|
const [season, setSeason] = useState<null | number>(null);
|
2023-10-31 13:30:47 -05:00
|
|
|
const { data: ratingsInfo } = useSWR(
|
2023-10-31 15:20:37 -05:00
|
|
|
`ratings-info-${region}-${season}`,
|
2023-10-31 13:30:47 -05:00
|
|
|
() =>
|
|
|
|
|
season === null
|
2023-10-31 15:20:37 -05:00
|
|
|
? getRatingsInfo(region)
|
2023-11-07 11:36:08 -06:00
|
|
|
: getArchivedRatingsInfo(region, season),
|
2023-10-31 13:15:28 -05:00
|
|
|
);
|
|
|
|
|
const [jumpToLeague, setJumpToLeague] = useState(0);
|
|
|
|
|
const { data: latestArchivedSeasonNumber } = useSWR<number>(
|
|
|
|
|
'/api/ratings/latest-archived-season-number',
|
|
|
|
|
numberFetcher,
|
|
|
|
|
);
|
2023-10-31 15:20:37 -05:00
|
|
|
const players = useSWR(`ratings-players-${region}-${season}`, () => {
|
2023-10-31 13:30:47 -05:00
|
|
|
if (season === null) {
|
|
|
|
|
// i'll deal with this later
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
2023-11-07 11:36:08 -06:00
|
|
|
return getArchivedRatingsLeaderboard(region, season);
|
2023-10-31 13:30:47 -05:00
|
|
|
}
|
|
|
|
|
});
|
2023-10-31 15:20:37 -05:00
|
|
|
const [page, setPage] = useState(0);
|
2023-11-07 10:32:01 -06:00
|
|
|
const [highlightedPlayerId, setHighlightedPlayerId] = useState<number | null>(
|
|
|
|
|
null,
|
|
|
|
|
);
|
2023-10-31 15:20:37 -05:00
|
|
|
const playerSlice = players.data?.slice(
|
2023-11-02 11:14:13 -05:00
|
|
|
page * rowsPerPage,
|
|
|
|
|
page * rowsPerPage + rowsPerPage,
|
2023-10-31 15:20:37 -05:00
|
|
|
);
|
2023-11-07 10:47:28 -06:00
|
|
|
const positionInput = useRef<HTMLInputElement>(null);
|
2023-11-07 11:50:51 -06:00
|
|
|
const scoreInput = useRef<HTMLInputElement>(null);
|
2023-11-07 10:06:15 -06:00
|
|
|
const previousPage = () => setPage((page) => Math.max(page - 1, 0));
|
|
|
|
|
const nextPage = () =>
|
|
|
|
|
setPage((page) =>
|
|
|
|
|
Math.min(page + 1, Math.floor((players.data?.length ?? 0) / rowsPerPage)),
|
|
|
|
|
);
|
2023-11-07 10:32:01 -06:00
|
|
|
const [searchResults, setSearchResults] = useState<AccountList | undefined>(
|
|
|
|
|
undefined,
|
|
|
|
|
);
|
|
|
|
|
const handleSearchPlayerChange = debounce(
|
|
|
|
|
async (event: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
const trimmedSearch = event.target.value.trim();
|
|
|
|
|
|
|
|
|
|
if (trimmedSearch) {
|
|
|
|
|
const encodedSearch = encodeURIComponent(trimmedSearch);
|
|
|
|
|
const accountList = await fetchBlitz<AccountList>(
|
2023-11-07 11:40:46 -06:00
|
|
|
`https://api.wotblitz.${region}/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=100`,
|
2023-11-07 10:32:01 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
setSearchResults(
|
|
|
|
|
accountList.filter(
|
|
|
|
|
(searchedPlayer) =>
|
|
|
|
|
players.data?.some(
|
|
|
|
|
(leaderboardPlayer) =>
|
|
|
|
|
leaderboardPlayer.id === searchedPlayer.account_id,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
setSearchResults(undefined);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
500,
|
|
|
|
|
);
|
2023-10-31 15:20:37 -05:00
|
|
|
|
|
|
|
|
cachePage(page - 1);
|
|
|
|
|
cachePage(page);
|
|
|
|
|
cachePage(page + 1);
|
|
|
|
|
|
|
|
|
|
function cachePage(page: number) {
|
|
|
|
|
const ids = players.data
|
2023-11-02 11:14:13 -05:00
|
|
|
?.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
|
2023-10-31 15:20:37 -05:00
|
|
|
.map(({ id }) => id)
|
|
|
|
|
.filter((id) => !(id in usernameCache[region]));
|
|
|
|
|
|
|
|
|
|
if (ids && ids.length > 0) {
|
|
|
|
|
getAccountInfo(region, ids).then((data) => {
|
2023-11-07 11:13:30 -06:00
|
|
|
data.map((player, index) => {
|
2023-10-31 15:20:37 -05:00
|
|
|
useUsernameCache.setState(
|
2023-11-07 11:13:30 -06:00
|
|
|
produce((draft: UsernameCache) => {
|
|
|
|
|
if (player) {
|
|
|
|
|
draft[region][ids[index]] = player.nickname;
|
|
|
|
|
} else {
|
|
|
|
|
draft[region][ids[index]] = null;
|
|
|
|
|
}
|
2023-10-31 15:20:37 -05:00
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
2023-10-31 15:31:03 -05:00
|
|
|
|
|
|
|
|
getClanAccountInfo(region, ids, ['clan']).then((data) => {
|
|
|
|
|
data.map((player) => {
|
|
|
|
|
useClanCache.setState(
|
|
|
|
|
produce((draft) => {
|
|
|
|
|
if (player) {
|
|
|
|
|
draft[region][player.account_id] =
|
|
|
|
|
player.clan?.tag ?? undefined;
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
2023-10-31 15:20:37 -05:00
|
|
|
}
|
|
|
|
|
}
|
2023-11-07 10:47:28 -06:00
|
|
|
const handleJumpToPosition = () => {
|
2023-11-07 11:50:51 -06:00
|
|
|
if (!players.data) return;
|
|
|
|
|
|
2023-11-07 10:47:28 -06:00
|
|
|
const rawPosition = positionInput.current!.valueAsNumber - 1;
|
|
|
|
|
const position = Math.max(
|
|
|
|
|
0,
|
|
|
|
|
Math.min(rawPosition, (players.data?.length ?? 0) - 1),
|
|
|
|
|
);
|
|
|
|
|
setPage(Math.floor(position / rowsPerPage));
|
|
|
|
|
|
|
|
|
|
if (players.data) {
|
|
|
|
|
setHighlightedPlayerId(players.data[position].id);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const [jumpToPositionOpen, setJumpToPositionOpen] = useState(false);
|
2023-11-07 11:50:51 -06:00
|
|
|
const handleJumpToScore = () => {
|
|
|
|
|
if (!players.data) return;
|
|
|
|
|
|
|
|
|
|
const playerIndex = findLastIndex(players.data, (player) => {
|
|
|
|
|
return player.score >= scoreInput.current!.valueAsNumber;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (playerIndex === -1) return;
|
|
|
|
|
|
|
|
|
|
setPage(Math.floor(playerIndex / rowsPerPage));
|
|
|
|
|
|
|
|
|
|
if (players.data) {
|
|
|
|
|
setHighlightedPlayerId(players.data[playerIndex].id);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const [jumpToScoreOpen, setJumpToScoreOpen] = useState(false);
|
2023-10-31 15:20:37 -05:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setPage(0);
|
|
|
|
|
}, [season, region]);
|
2023-10-29 13:40:32 -05:00
|
|
|
|
2023-11-07 10:06:15 -06:00
|
|
|
function PageTurner() {
|
|
|
|
|
const pageInput = useRef<HTMLInputElement>(null);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (pageInput.current) pageInput.current.value = `${page + 1}`;
|
|
|
|
|
}, [page]);
|
|
|
|
|
|
|
|
|
|
return (
|
2023-11-07 10:50:41 -06:00
|
|
|
<Flex justify="center" wrap="wrap" gap="2">
|
|
|
|
|
<Select.Root
|
|
|
|
|
onValueChange={(value) => setRowsPerPage(parseInt(value))}
|
|
|
|
|
defaultValue={`${rowsPerPage}`}
|
|
|
|
|
>
|
|
|
|
|
<Select.Trigger />
|
|
|
|
|
|
|
|
|
|
<Select.Content>
|
|
|
|
|
{ROWS_OPTIONS.map((size) => (
|
|
|
|
|
<Select.Item value={`${size}`} key={size}>
|
|
|
|
|
{size} per page
|
|
|
|
|
</Select.Item>
|
|
|
|
|
))}
|
|
|
|
|
</Select.Content>
|
|
|
|
|
</Select.Root>
|
2023-11-07 11:50:51 -06:00
|
|
|
|
|
|
|
|
<Flex gap="2">
|
|
|
|
|
<Button variant="soft" onClick={previousPage}>
|
|
|
|
|
<CaretLeftIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
<TextField.Root className={noArrows}>
|
|
|
|
|
<TextField.Slot>Page</TextField.Slot>
|
|
|
|
|
<TextField.Input
|
|
|
|
|
className={noArrows}
|
|
|
|
|
type="number"
|
|
|
|
|
ref={pageInput}
|
|
|
|
|
style={{ width: 64, textAlign: 'center' }}
|
|
|
|
|
onBlur={(event) => {
|
|
|
|
|
setPage(
|
|
|
|
|
Math.max(
|
|
|
|
|
0,
|
|
|
|
|
Math.min(
|
|
|
|
|
Math.floor((players.data?.length ?? 0) / rowsPerPage),
|
|
|
|
|
event.target.valueAsNumber - 1,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
|
if (event.key === 'Enter') {
|
|
|
|
|
(event.target as HTMLInputElement).blur();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<TextField.Slot>
|
|
|
|
|
out of {Math.ceil((players.data?.length ?? 0) / rowsPerPage)}
|
|
|
|
|
</TextField.Slot>
|
|
|
|
|
</TextField.Root>
|
|
|
|
|
<Button variant="soft" onClick={nextPage}>
|
|
|
|
|
<CaretRightIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
</Flex>
|
2023-11-07 10:50:41 -06:00
|
|
|
</Flex>
|
2023-11-07 10:06:15 -06:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-29 13:40:32 -05:00
|
|
|
return (
|
2023-11-07 10:32:01 -06:00
|
|
|
<PageWrapper color="orange">
|
2023-10-31 15:20:37 -05:00
|
|
|
<Flex gap="2">
|
2023-10-29 13:40:32 -05:00
|
|
|
<Select.Root
|
2023-10-31 15:20:37 -05:00
|
|
|
defaultValue={region}
|
2023-10-31 15:24:00 -05:00
|
|
|
onValueChange={(value) => setRegion(value as Region)}
|
2023-10-29 13:40:32 -05:00
|
|
|
>
|
|
|
|
|
<Select.Trigger style={{ flex: 1 }} />
|
|
|
|
|
|
|
|
|
|
<Select.Content>
|
2023-10-30 21:57:22 -05:00
|
|
|
{REGIONS.map((region) => (
|
|
|
|
|
<Select.Item key={region} value={region}>
|
|
|
|
|
{REGION_NAMES[region]}
|
|
|
|
|
</Select.Item>
|
|
|
|
|
))}
|
2023-10-29 13:40:32 -05:00
|
|
|
</Select.Content>
|
|
|
|
|
</Select.Root>
|
2023-10-30 21:57:22 -05:00
|
|
|
|
2023-10-29 13:40:32 -05:00
|
|
|
<Select.Root
|
2023-10-30 21:57:22 -05:00
|
|
|
value={`${season}`}
|
2023-10-29 13:40:32 -05:00
|
|
|
onValueChange={(value) =>
|
2023-10-30 21:57:22 -05:00
|
|
|
setSeason(value === 'null' ? null : parseInt(value))
|
2023-10-29 13:40:32 -05:00
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<Select.Trigger style={{ flex: 1 }} />
|
|
|
|
|
|
|
|
|
|
<Select.Content>
|
2023-10-30 21:57:22 -05:00
|
|
|
{ratingsInfo?.detail === undefined && (
|
|
|
|
|
<Select.Item value="null">Current season</Select.Item>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<Select.Group>
|
|
|
|
|
<Select.Label>Archives</Select.Label>
|
|
|
|
|
|
|
|
|
|
{latestArchivedSeasonNumber &&
|
|
|
|
|
range(
|
|
|
|
|
FIRST_ARCHIVED_RATINGS_SEASON,
|
|
|
|
|
latestArchivedSeasonNumber + 1,
|
|
|
|
|
)
|
|
|
|
|
.map((season) => (
|
|
|
|
|
<Select.Item key={season} value={`${season}`}>
|
|
|
|
|
Season {season}
|
|
|
|
|
</Select.Item>
|
|
|
|
|
))
|
|
|
|
|
.reverse()}
|
|
|
|
|
</Select.Group>
|
2023-10-29 13:40:32 -05:00
|
|
|
</Select.Content>
|
|
|
|
|
</Select.Root>
|
|
|
|
|
</Flex>
|
2023-10-31 13:30:47 -05:00
|
|
|
|
2023-11-07 11:50:51 -06:00
|
|
|
<Flex gap="2" justify="center" wrap="wrap">
|
|
|
|
|
<Dialog.Root open={jumpToScoreOpen} onOpenChange={setJumpToScoreOpen}>
|
|
|
|
|
<Dialog.Trigger>
|
|
|
|
|
<Button variant="soft">Jump to score</Button>
|
|
|
|
|
</Dialog.Trigger>
|
|
|
|
|
|
|
|
|
|
<Dialog.Content>
|
|
|
|
|
<Flex gap="4" justify="center">
|
|
|
|
|
<TextField.Input
|
|
|
|
|
ref={scoreInput}
|
|
|
|
|
onChange={handleSearchPlayerChange}
|
|
|
|
|
type="number"
|
|
|
|
|
placeholder="Type a score..."
|
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
|
if (event.key === 'Enter') {
|
|
|
|
|
handleJumpToScore();
|
|
|
|
|
setJumpToScoreOpen(false);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<Flex gap="2">
|
|
|
|
|
<Dialog.Close>
|
|
|
|
|
<Button color="red">Cancel</Button>
|
|
|
|
|
</Dialog.Close>
|
|
|
|
|
<Dialog.Close>
|
|
|
|
|
<Button onClick={handleJumpToScore}>Jump</Button>
|
|
|
|
|
</Dialog.Close>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Dialog.Content>
|
|
|
|
|
</Dialog.Root>
|
|
|
|
|
|
2023-11-07 10:47:28 -06:00
|
|
|
<Dialog.Root
|
|
|
|
|
open={jumpToPositionOpen}
|
|
|
|
|
onOpenChange={setJumpToPositionOpen}
|
|
|
|
|
>
|
|
|
|
|
<Dialog.Trigger>
|
2023-11-07 11:50:51 -06:00
|
|
|
<Button variant="soft">Jump to position</Button>
|
2023-11-07 10:47:28 -06:00
|
|
|
</Dialog.Trigger>
|
|
|
|
|
|
|
|
|
|
<Dialog.Content>
|
|
|
|
|
<Flex gap="4" justify="center">
|
|
|
|
|
<TextField.Input
|
|
|
|
|
ref={positionInput}
|
|
|
|
|
onChange={handleSearchPlayerChange}
|
|
|
|
|
type="number"
|
|
|
|
|
placeholder="Type a position..."
|
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
|
if (event.key === 'Enter') {
|
|
|
|
|
handleJumpToPosition();
|
|
|
|
|
setJumpToPositionOpen(false);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<Flex gap="2">
|
|
|
|
|
<Dialog.Close>
|
|
|
|
|
<Button color="red">Cancel</Button>
|
|
|
|
|
</Dialog.Close>
|
|
|
|
|
<Dialog.Close>
|
|
|
|
|
<Button onClick={handleJumpToPosition}>Jump</Button>
|
|
|
|
|
</Dialog.Close>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Dialog.Content>
|
|
|
|
|
</Dialog.Root>
|
|
|
|
|
|
2023-11-07 11:02:11 -06:00
|
|
|
<Dialog.Root>
|
|
|
|
|
<Dialog.Trigger>
|
2023-11-07 11:50:51 -06:00
|
|
|
<Button variant="soft">Jump to league</Button>
|
2023-11-07 11:02:11 -06:00
|
|
|
</Dialog.Trigger>
|
2023-11-07 10:47:28 -06:00
|
|
|
|
2023-11-07 11:02:11 -06:00
|
|
|
<Dialog.Content>
|
2023-11-07 10:47:28 -06:00
|
|
|
<Flex direction="column" gap="2">
|
|
|
|
|
<Select.Root
|
|
|
|
|
value={`${jumpToLeague}`}
|
|
|
|
|
onValueChange={(value) => setJumpToLeague(parseInt(value))}
|
|
|
|
|
>
|
|
|
|
|
<Select.Trigger />
|
|
|
|
|
|
|
|
|
|
<Select.Content>
|
|
|
|
|
{ratingsInfo?.detail === undefined &&
|
|
|
|
|
ratingsInfo?.leagues.map(({ index, title }) => (
|
|
|
|
|
<Select.Item key={index} value={`${index}`}>
|
|
|
|
|
{title}
|
|
|
|
|
</Select.Item>
|
|
|
|
|
))}
|
|
|
|
|
</Select.Content>
|
|
|
|
|
</Select.Root>
|
|
|
|
|
|
|
|
|
|
<Flex gap="2">
|
2023-11-07 11:02:11 -06:00
|
|
|
<Dialog.Close>
|
2023-11-07 10:47:28 -06:00
|
|
|
<Button color="red">Cancel</Button>
|
2023-11-07 11:02:11 -06:00
|
|
|
</Dialog.Close>
|
|
|
|
|
<Dialog.Close>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => {
|
|
|
|
|
if (!ratingsInfo || ratingsInfo.detail || !players.data)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const minScore =
|
|
|
|
|
LEAGUES[jumpToLeague - 1]?.minScore ?? Infinity;
|
|
|
|
|
const firstPlayerIndex = players.data.findIndex(
|
|
|
|
|
(player) => player.score < minScore,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (firstPlayerIndex === -1) return;
|
|
|
|
|
|
|
|
|
|
setPage(Math.floor(firstPlayerIndex / rowsPerPage));
|
|
|
|
|
setHighlightedPlayerId(players.data[firstPlayerIndex].id);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Jump
|
|
|
|
|
</Button>
|
|
|
|
|
</Dialog.Close>
|
2023-11-07 10:47:28 -06:00
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
2023-11-07 11:02:11 -06:00
|
|
|
</Dialog.Content>
|
|
|
|
|
</Dialog.Root>
|
2023-11-07 10:47:28 -06:00
|
|
|
|
|
|
|
|
<Dialog.Root>
|
|
|
|
|
<Dialog.Trigger>
|
2023-11-07 11:50:51 -06:00
|
|
|
<Button variant="soft">Jump to player</Button>
|
2023-11-07 10:47:28 -06:00
|
|
|
</Dialog.Trigger>
|
|
|
|
|
|
|
|
|
|
<Dialog.Content>
|
|
|
|
|
<Flex gap="4" direction="column">
|
|
|
|
|
<TextField.Root>
|
|
|
|
|
<TextField.Slot>
|
|
|
|
|
<MagnifyingGlassIcon height="16" width="16" />
|
|
|
|
|
</TextField.Slot>
|
|
|
|
|
|
|
|
|
|
<TextField.Input
|
|
|
|
|
onChange={handleSearchPlayerChange}
|
|
|
|
|
placeholder="Search for player..."
|
|
|
|
|
/>
|
|
|
|
|
</TextField.Root>
|
|
|
|
|
|
|
|
|
|
<Flex direction="column" gap="2">
|
|
|
|
|
{searchResults?.map((player) => (
|
|
|
|
|
<Dialog.Close>
|
|
|
|
|
<Button
|
|
|
|
|
key={player.account_id}
|
|
|
|
|
variant="ghost"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
const playerIndex = players.data?.findIndex(
|
|
|
|
|
(playerData) => playerData.id === player.account_id,
|
|
|
|
|
);
|
|
|
|
|
const playerPage = Math.floor(
|
|
|
|
|
playerIndex! / rowsPerPage,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
setPage(playerPage);
|
|
|
|
|
setHighlightedPlayerId(player.account_id);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{player.nickname}
|
|
|
|
|
</Button>
|
|
|
|
|
</Dialog.Close>
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
|
|
{searchResults?.length === 0 && (
|
|
|
|
|
<Button disabled variant="ghost">
|
|
|
|
|
No players found in leaderboard
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</Flex>
|
|
|
|
|
|
|
|
|
|
<Flex gap="2">
|
|
|
|
|
<Dialog.Close>
|
|
|
|
|
<Button color="red">Cancel</Button>
|
|
|
|
|
</Dialog.Close>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Dialog.Content>
|
|
|
|
|
</Dialog.Root>
|
2023-10-31 15:20:37 -05:00
|
|
|
</Flex>
|
|
|
|
|
|
2023-11-07 10:50:41 -06:00
|
|
|
<PageTurner />
|
|
|
|
|
|
2023-10-31 15:20:37 -05:00
|
|
|
<Leaderboard.Root>
|
2023-11-07 10:06:15 -06:00
|
|
|
{players.isLoading ? (
|
|
|
|
|
<Leaderboard.Gap message="Loading players..." />
|
|
|
|
|
) : (
|
|
|
|
|
playerSlice?.map((player, index) => (
|
|
|
|
|
<Leaderboard.Item
|
|
|
|
|
nickname={
|
2023-11-07 11:13:30 -06:00
|
|
|
usernameCache[region][player.id] === null
|
|
|
|
|
? `Deleted player ${player.id}`
|
|
|
|
|
: usernameCache[region][player.id]
|
|
|
|
|
? usernameCache[region][player.id]!
|
|
|
|
|
: `Loading player ${player.id}...`
|
2023-11-07 10:06:15 -06:00
|
|
|
}
|
|
|
|
|
position={page * rowsPerPage + index + 1}
|
|
|
|
|
score={player.score}
|
|
|
|
|
clan={clanCache[region][player.id]}
|
|
|
|
|
key={player.id}
|
2023-11-07 10:32:01 -06:00
|
|
|
highlight={highlightedPlayerId === player.id}
|
2023-11-07 10:06:15 -06:00
|
|
|
/>
|
|
|
|
|
))
|
|
|
|
|
)}
|
2023-10-31 15:20:37 -05:00
|
|
|
</Leaderboard.Root>
|
2023-10-31 13:30:47 -05:00
|
|
|
|
2023-11-07 10:50:41 -06:00
|
|
|
<PageTurner />
|
2023-10-29 13:40:32 -05:00
|
|
|
</PageWrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|