mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: options for ratings tool
This commit is contained in:
1 parent
8cd1a70333
commit
93ffe5c507
5 files changed
+124
-4
No files matched your search
@@ -0,0 +1,10 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { Region } from '../../../../constants/regions';
|
||||
import getRatingsInfo from '../../../../core/blitz/getRatingsInfo';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { region: Region } },
|
||||
) {
|
||||
return NextResponse.json(await getRatingsInfo(params.region));
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
'use client';
|
||||
|
||||
import { Flex, Select } from '@radix-ui/themes';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { RatingsInfo } from '../../../commands/ratings';
|
||||
import PageWrapper from '../../../components/PageWrapper';
|
||||
import { Region } from '../../../constants/regions';
|
||||
import getRatingsInfo from '../../../core/blitz/getRatingsInfo';
|
||||
import { RatingsType, useRatings } from '../../../stores/ratings';
|
||||
|
||||
export default function Page() {
|
||||
const ratings = useRatings();
|
||||
const [awaitedRatingsInfo, setRatingsInfo] = useState<RatingsInfo | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
getRatingsInfo(ratings.region).then(setRatingsInfo);
|
||||
}, [ratings.region]);
|
||||
|
||||
return (
|
||||
<PageWrapper>
|
||||
<Flex gap="2">
|
||||
<Select.Root
|
||||
defaultValue={ratings.region}
|
||||
onValueChange={(value) =>
|
||||
useRatings.setState({ region: value as Region })
|
||||
}
|
||||
>
|
||||
<Select.Trigger style={{ flex: 1 }} />
|
||||
|
||||
<Select.Content>
|
||||
<Select.Item value="com">North America</Select.Item>
|
||||
<Select.Item value="eu">Europe</Select.Item>
|
||||
<Select.Item value="asia">Asia</Select.Item>
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
<Select.Root
|
||||
defaultValue={ratings.type}
|
||||
onValueChange={(value) =>
|
||||
useRatings.setState({ type: value as RatingsType })
|
||||
}
|
||||
>
|
||||
<Select.Trigger style={{ flex: 1 }} />
|
||||
|
||||
<Select.Content>
|
||||
<Select.Item value="league">League</Select.Item>
|
||||
<Select.Item value="neighbors">Neighbors</Select.Item>
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
|
||||
{ratings.type === 'league' ? (
|
||||
<Select.Root
|
||||
defaultValue={`${ratings.league}`}
|
||||
onValueChange={(value) =>
|
||||
useRatings.setState({ league: parseInt(value) })
|
||||
}
|
||||
>
|
||||
<Select.Trigger style={{ flex: 1 }} />
|
||||
|
||||
<Select.Content>
|
||||
{awaitedRatingsInfo?.detail === undefined &&
|
||||
awaitedRatingsInfo?.leagues.map((league) => (
|
||||
<Select.Item key={league.index} value={`${league.index}`}>
|
||||
{league.title}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
) : (
|
||||
'1'
|
||||
)}
|
||||
</Flex>
|
||||
</PageWrapper>
|
||||
);
|
||||
}
|
||||
@@ -15,7 +15,6 @@ export const TOOLS: Tool[] = [
|
||||
id: 'ratings',
|
||||
title: 'Ratings',
|
||||
description: 'Current and old season leader boards',
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
id: 'tankopedia',
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { RatingsInfo } from '../../commands/ratings';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { context } from '../blitzkrieg/context';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
|
||||
export default async function getRatingsInfo(region: Region) {
|
||||
const response = await fetch(
|
||||
`https://${regionToRegionSubdomain(
|
||||
region,
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||
context === 'bot'
|
||||
? `https://${regionToRegionSubdomain(
|
||||
region,
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/season/`
|
||||
: `/api/ratings-info/${region}`,
|
||||
);
|
||||
|
||||
return (await response.json()) as Promise<RatingsInfo>;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { create } from 'zustand';
|
||||
import { devtools, persist } from 'zustand/middleware';
|
||||
import { Region } from '../constants/regions';
|
||||
|
||||
export type RatingsType = 'neighbors' | 'league';
|
||||
|
||||
interface Ratings {
|
||||
type: RatingsType;
|
||||
/**
|
||||
* When null, the current season is used unless there ain't one in which case
|
||||
* we do whatever lol
|
||||
*/
|
||||
season: number | null;
|
||||
region: Region;
|
||||
league: number;
|
||||
}
|
||||
|
||||
export const useRatings = create<Ratings>()(
|
||||
devtools(
|
||||
persist(
|
||||
(set) => ({
|
||||
type: 'league',
|
||||
season: null,
|
||||
league: 0,
|
||||
region: 'com',
|
||||
}),
|
||||
{
|
||||
name: 'ratings',
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
Reference in new issue
Block a user