Skip to content

Commit

Permalink
Do not use calculated game players for penalty - use all round players.
Browse files Browse the repository at this point in the history
  • Loading branch information
uncaught committed Jan 12, 2020
1 parent 17b404a commit 6cbc4f1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
9 changes: 5 additions & 4 deletions client/src/pages/game/Penalty.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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';

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);
Expand Down Expand Up @@ -49,7 +50,7 @@ export default function Penalty(): ReactElement {
onChange={() => patchGame({data: {contra: {members: gameOtherPlayerIds}}})}
/>
</Form.Field>
{activePlayers.length > 4 && <>
{roundParticipatingPlayers.length > 4 && <>
<Form.Field>
<Checkbox
radio
Expand Down
7 changes: 4 additions & 3 deletions client/src/store/Games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {useCallback, useMemo} from 'react';
import {LoguxDispatch} from './Logux';
import {useRound} from './Rounds';
import {difference} from 'lodash';
import {useGameParticipatingPlayers, usePlayersWithStats} from './Players';
import {usePlayersWithStats, useRoundParticipatingPlayers} from './Players';
import {useHistory} from 'react-router-dom';
import {useGroup} from './Groups';
import {detectRunNumber} from './Games/DetectRunNumber';
Expand Down Expand Up @@ -104,7 +104,7 @@ export function useAddGame() {
const {settings} = useGroup()!;
const round = useRound()!;
const currentGames = useSortedGames();
const players = useGameParticipatingPlayers();
const roundParticipatingPlayers = useRoundParticipatingPlayers();
const playersWithStats = usePlayersWithStats();
const history = useHistory();
const dispatch = useDispatch<LoguxDispatch>();
Expand All @@ -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);
Expand All @@ -132,7 +133,7 @@ export function useAddGame() {
};
dispatch.sync<GamesAdd>({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() {
Expand Down
8 changes: 0 additions & 8 deletions client/src/store/Players.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6cbc4f1

Please sign in to comment.