diff --git a/.vscode/settings.json b/.vscode/settings.json index 5f186195b..0636a141e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -39,7 +39,8 @@ "vitepress", "wargaming", "webp", - "winrate" + "winrate", + "zustand" ], "deno.enable": false, "deno.unstable": false diff --git a/package.json b/package.json index 226376aa0..cde9c75da 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "satori": "^0.10.4", "vite-node": "^0.34.4", "vitepress": "^1.0.0-rc.12", - "vitepress-plugin-auto-sidebar": "^1.1.0" + "vitepress-plugin-auto-sidebar": "^1.1.0", + "zustand": "^4.4.1" }, "devDependencies": { "@total-typescript/ts-reset": "^0.5.1", diff --git a/src/app/api/list/players/route.ts b/src/app/api/search/players/route.ts similarity index 100% rename from src/app/api/list/players/route.ts rename to src/app/api/search/players/route.ts diff --git a/src/app/api/stats/normalized/tanks/route.ts b/src/app/api/stats/normalized/tanks/route.ts new file mode 100644 index 000000000..dc6fc5d3c --- /dev/null +++ b/src/app/api/stats/normalized/tanks/route.ts @@ -0,0 +1,16 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { Region } from '../../../../../constants/regions'; +import getTankStats from '../../../../../core/blitz/getTankStats'; +import { NormalizedTankStats } from '../../../../../types/tanksStats'; + +export async function GET(request: NextRequest) { + const region = request.nextUrl.searchParams.get('region') as Region; + const id = parseInt(request.nextUrl.searchParams.get('id')!); + const tankStats = await getTankStats(region, id); + const normalized = tankStats.reduce( + (accumulator, tank) => ({ ...accumulator, [tank.tank_id]: tank }), + {}, + ); + + return NextResponse.json(normalized); +} diff --git a/src/app/tools/session/page.tsx b/src/app/tools/session/page.tsx index b93def02e..f14f304ee 100644 --- a/src/app/tools/session/page.tsx +++ b/src/app/tools/session/page.tsx @@ -9,6 +9,8 @@ import { SearchBar } from '../../../components/SearchBar'; import { REGION_NAMES } from '../../../constants/regions'; import { AccountListWithServer } from '../../../core/blitz/listPlayers'; import { theme } from '../../../stitches.config'; +import { useSession } from '../../../stores/session'; +import { NormalizedTankStats } from '../../../types/tanksStats'; import * as styles from './page.css'; export default function Page() { @@ -21,7 +23,7 @@ export default function Page() { async (event: ChangeEvent) => { if (event.target.value) { const players = await fetch( - `/api/list/players?search=${event.target.value}`, + `/api/search/players?search=${event.target.value}`, ).then((response) => response.json() as Promise); setSearchResults(players); @@ -31,6 +33,7 @@ export default function Page() { }, 500, ); + const initialSession = useSession.getState(); return ( @@ -39,6 +42,9 @@ export default function Page() { { if (event.target.value) { setShowSearchResults(true); @@ -93,13 +99,30 @@ export default function Page() { No results ) : ( - searchResults?.map(({ account_id, nickname, region }) => ( + searchResults?.map(({ account_id: id, nickname, region }) => (