2023-10-29 13:40:32 -05:00
|
|
|
'use client';
|
|
|
|
|
|
2023-10-30 21:57:22 -05:00
|
|
|
import { MagnifyingGlassIcon } from '@radix-ui/react-icons';
|
|
|
|
|
import { Button, Flex, Popover, Select, TextField } from '@radix-ui/themes';
|
|
|
|
|
import { range } from 'lodash';
|
2023-10-31 13:15:28 -05:00
|
|
|
import { useState } from 'react';
|
|
|
|
|
import useSWR from 'swr';
|
2023-10-29 13:40:32 -05:00
|
|
|
import PageWrapper from '../../../components/PageWrapper';
|
2023-10-30 21:57:22 -05:00
|
|
|
import { REGIONS, REGION_NAMES, Region } from '../../../constants/regions';
|
2023-10-31 12:35:32 -05:00
|
|
|
import getRatingsInfo from '../../../core/blitz/getRatingsInfo';
|
2023-10-31 12:58:24 -05:00
|
|
|
import getArchivedRatingsInfoAPI from '../../../core/blitzkrieg/getArchivedRatingsInfoAPI';
|
2023-10-31 13:15:28 -05:00
|
|
|
import { numberFetcher } from '../../../core/blitzkrieg/numberFetcher';
|
2023-10-30 21:57:22 -05:00
|
|
|
import { useRatings } from '../../../stores/ratings';
|
2023-10-29 13:40:32 -05:00
|
|
|
|
2023-10-31 13:15:28 -05:00
|
|
|
export const FIRST_ARCHIVED_RATINGS_SEASON = 49;
|
|
|
|
|
|
2023-10-29 13:40:32 -05:00
|
|
|
export default function Page() {
|
|
|
|
|
const ratings = useRatings();
|
2023-10-30 21:57:22 -05:00
|
|
|
// null being the latest season
|
|
|
|
|
const [season, setSeason] = useState<null | number>(null);
|
2023-10-31 13:15:28 -05:00
|
|
|
const { data: ratingsInfo } = useSWR(`ratings-info-${season}`, () =>
|
|
|
|
|
season === null
|
|
|
|
|
? getRatingsInfo(ratings.region)
|
|
|
|
|
: getArchivedRatingsInfoAPI(ratings.region, season),
|
|
|
|
|
);
|
|
|
|
|
const [jumpToLeague, setJumpToLeague] = useState(0);
|
|
|
|
|
const { data: latestArchivedSeasonNumber } = useSWR<number>(
|
|
|
|
|
'/api/ratings/latest-archived-season-number',
|
|
|
|
|
numberFetcher,
|
|
|
|
|
);
|
2023-10-29 13:40:32 -05:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<PageWrapper>
|
2023-10-30 21:57:22 -05:00
|
|
|
<Flex gap="2" wrap="wrap">
|
2023-10-29 13:40:32 -05:00
|
|
|
<Select.Root
|
|
|
|
|
defaultValue={ratings.region}
|
|
|
|
|
onValueChange={(value) =>
|
|
|
|
|
useRatings.setState({ region: value as Region })
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<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>
|
|
|
|
|
|
2023-10-30 21:57:22 -05:00
|
|
|
<Popover.Root>
|
|
|
|
|
<Popover.Trigger>
|
|
|
|
|
<Button variant="soft">Jump to league</Button>
|
|
|
|
|
</Popover.Trigger>
|
2023-10-29 13:40:32 -05:00
|
|
|
|
2023-10-30 21:57:22 -05:00
|
|
|
<Popover.Content>
|
|
|
|
|
<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">
|
|
|
|
|
<Popover.Close>
|
|
|
|
|
<Button color="red">Cancel</Button>
|
|
|
|
|
</Popover.Close>
|
|
|
|
|
|
|
|
|
|
<Popover.Close>
|
|
|
|
|
<Button>Jump</Button>
|
|
|
|
|
</Popover.Close>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Popover.Content>
|
|
|
|
|
</Popover.Root>
|
|
|
|
|
|
|
|
|
|
<Popover.Root>
|
|
|
|
|
<Popover.Trigger>
|
|
|
|
|
<Button variant="soft">Jump to player</Button>
|
|
|
|
|
</Popover.Trigger>
|
|
|
|
|
|
|
|
|
|
<Popover.Content>
|
|
|
|
|
<Flex gap="2" direction="column">
|
|
|
|
|
<TextField.Root>
|
|
|
|
|
<TextField.Slot>
|
|
|
|
|
<MagnifyingGlassIcon height="16" width="16" />
|
|
|
|
|
</TextField.Slot>
|
|
|
|
|
|
|
|
|
|
<TextField.Input placeholder="Search for player..." />
|
|
|
|
|
</TextField.Root>
|
|
|
|
|
|
|
|
|
|
<Flex gap="2">
|
|
|
|
|
<Popover.Close>
|
|
|
|
|
<Button color="red">Cancel</Button>
|
|
|
|
|
</Popover.Close>
|
|
|
|
|
|
|
|
|
|
<Popover.Close>
|
|
|
|
|
<Button>Jump</Button>
|
|
|
|
|
</Popover.Close>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Popover.Content>
|
|
|
|
|
</Popover.Root>
|
2023-10-29 13:40:32 -05:00
|
|
|
</Flex>
|
|
|
|
|
</PageWrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|