diff --git a/app/api/game/route.ts b/app/api/game/route.ts index 0df57f5f..9b84f9a0 100644 --- a/app/api/game/route.ts +++ b/app/api/game/route.ts @@ -1,7 +1,7 @@ import { revalidatePath } from 'next/cache' import { NextResponse } from 'next/server' -import { createGameType } from '@common/types' +import { AddedGameResponse, createGameType } from '@common/types' import { createGame, removeLatestGame } from '@server/db/games' import { formatRecentGame } from '@server/db/games/derivatives' @@ -12,7 +12,11 @@ export async function POST(req: Request) { const jsonGame = formatRecentGame(game) revalidatePath('/stats') - return NextResponse.json({ recentGame: jsonGame, winner: game.winner, loser: game.loser }) + return NextResponse.json({ + recentGame: jsonGame, + winner: game.winner, + loser: game.loser, + } as AddedGameResponse) } export async function DELETE() { diff --git a/app/components/Homepage/AddGame/AddGameModal/Content/GameCreation/index.tsx b/app/components/Homepage/AddGame/AddGameModal/Content/GameCreation/index.tsx index e08b4193..5411a88a 100644 --- a/app/components/Homepage/AddGame/AddGameModal/Content/GameCreation/index.tsx +++ b/app/components/Homepage/AddGame/AddGameModal/Content/GameCreation/index.tsx @@ -1,7 +1,7 @@ import { Dispatch, SetStateAction } from 'react' -import { RecentGame } from '@common/types' -import Player from '@server/models/rawModels/Player' +import { AddedGameResponse, RecentGame } from '@common/types' +import useSeasonalMode from '@hooks/useSeasonalMode' import { addToRecentPlayers, setPlayerId, setUndertable, useModalState } from '@state/Modal' import { removeFromQueue, useQueueState } from '@state/Queue' @@ -15,6 +15,7 @@ interface Props { } const GameCreation = ({ setGames, onClose }: Props) => { + const { seasonal } = useSeasonalMode() const [{ game }, dispatchModal] = useModalState() const [_, dispatchQueue] = useQueueState() @@ -32,9 +33,18 @@ const GameCreation = ({ setGames, onClose }: Props) => { }, body: JSON.stringify(game), }) - const data = await res.json() + const data = (await res.json()) as unknown as AddedGameResponse dispatchModal( - addToRecentPlayers([data.loser as unknown as Player, data.winner as unknown as Player]) + addToRecentPlayers([ + { + ...data.loser, + elo: seasonal ? data.loser.seasonElo ?? 400 : data.loser.elo, + }, + { + ...data.loser, + elo: seasonal ? data.loser.seasonElo ?? 400 : data.loser.elo, + }, + ]) ) dispatchModal(setPlayerId('winner', undefined)) dispatchModal(setPlayerId('loser', undefined)) diff --git a/app/components/Homepage/AddGame/AddGameModal/Content/PlayerSelection/SelectedPlayer/EloMeter.tsx b/app/components/Homepage/AddGame/AddGameModal/Content/PlayerSelection/SelectedPlayer/EloMeter.tsx index 17393ebb..fcbe9bca 100644 --- a/app/components/Homepage/AddGame/AddGameModal/Content/PlayerSelection/SelectedPlayer/EloMeter.tsx +++ b/app/components/Homepage/AddGame/AddGameModal/Content/PlayerSelection/SelectedPlayer/EloMeter.tsx @@ -3,15 +3,18 @@ import { memo } from 'react' import GaugeChart from 'react-gauge-chart' import type { Player } from '@common/types' +import useSeasonalMode from '@hooks/useSeasonalMode' import styles from './SelectedPlayer.module.scss' // API: https://github.com/Martin36/react-gauge-chart const EloMeter = ({ player }: { player: Player }) => { + const { seasonal } = useSeasonalMode() + const elo = seasonal ? player.seasonElo ?? 400 : player.elo const MIN_ELO = 0 const MAX_ELO = 800 - const pointerPosition = player.elo / MAX_ELO + const pointerPosition = elo / MAX_ELO return (