diff --git a/client/src/pages/game/Penalty.tsx b/client/src/pages/game/Penalty.tsx index 732a2f2..7a0c220 100644 --- a/client/src/pages/game/Penalty.tsx +++ b/client/src/pages/game/Penalty.tsx @@ -1,6 +1,6 @@ import React, {ReactElement, useCallback, useEffect, useState} from 'react'; import {Button, Checkbox, Form, Header, Icon, Modal, Segment} from 'semantic-ui-react'; -import {useGameParticipatingPlayers} from '../../store/Players'; +import {useRoundParticipatingPlayers} from '../../store/Players'; import {useGame, usePatchGame} from '../../store/Games'; import {useGroupMembers} from '../../store/GroupMembers'; @@ -8,9 +8,10 @@ export default function Penalty(): ReactElement { const {data} = useGame()!; const patchGame = usePatchGame(); const members = useGroupMembers(); - const activePlayers = useGameParticipatingPlayers(); + const roundParticipatingPlayers = useRoundParticipatingPlayers(); const penaltyMemId = data.gameTypeMemberId; - const allOtherPlayerIds = activePlayers.map(({groupMemberId}) => groupMemberId).filter((id) => id !== penaltyMemId); + const allOtherPlayerIds = roundParticipatingPlayers.map(({groupMemberId}) => groupMemberId) + .filter((id) => id !== penaltyMemId); const contraLength = data.contra.members.length; const gameOtherPlayerIds = data.players.filter((id) => id !== penaltyMemId); const [open, setOpen] = useState(false); @@ -49,7 +50,7 @@ export default function Penalty(): ReactElement { onChange={() => patchGame({data: {contra: {members: gameOtherPlayerIds}}})} /> - {activePlayers.length > 4 && <> + {roundParticipatingPlayers.length > 4 && <> (); @@ -117,6 +117,7 @@ export function useAddGame() { if ((lastGame && lastGame.data.isLastGame) || round.endDate) { return; } + const players = roundParticipatingPlayers.filter((p) => p.leftAfterGameNumber === null); const nextDealerId = lastGame ? getNextDealer(players, lastGame) : players[0].groupMemberId; const data = getDefaultGameData(settings, lastGame); data.runNumber = detectRunNumber(currentGames, nextDealerId); @@ -132,7 +133,7 @@ export function useAddGame() { }; dispatch.sync({game, type: 'games/add'}); history.push(`/groups/group/${round.groupId}/rounds/round/${round.id}/games/game/${id}`); - }, [currentGames, round, dispatch, history, players, playersWithStats, settings]); + }, [round, currentGames, roundParticipatingPlayers, settings, playersWithStats, dispatch, history]); } export function useRemoveGame() { diff --git a/client/src/store/Players.ts b/client/src/store/Players.ts index e8269d6..3a4d948 100644 --- a/client/src/store/Players.ts +++ b/client/src/store/Players.ts @@ -85,14 +85,6 @@ export function useRoundParticipatingPlayers(): Player[] { return useMemo(() => players.filter((p) => p.leftAfterGameNumber !== 0), [players]); } -/** - * Includes only players that have not left - */ -export function useGameParticipatingPlayers(): Player[] { - const players = usePlayers(); - return useMemo(() => players.filter((p) => p.leftAfterGameNumber === null), [players]); -} - export interface PlayerStats { member: GroupMember; player: Player;