GameProposal: Cancel

show button only if cancelable game is selected
This commit is contained in:
djmil 2023-11-15 09:15:38 +01:00
parent 6dea7ae63f
commit 9c8e296684
5 changed files with 41 additions and 10 deletions

View File

@ -1,6 +1,15 @@
import React from 'react';
import React, { useContext } from 'react';
import { GamesContext } from '../../../context/games';
export default function Accept() {
const games = useContext(GamesContext);
return <button className='Accept'>Accept</button>
}
const selectedGame = games.findGame({ uuid: games.proposal.selectedUUID });
if (selectedGame?.status !== 'GAME_PROPOSAL_WAIT_FOR_OPPONENT')
return (
<button className='Accept'>
Accept
</button>
)
}

View File

@ -1,6 +1,15 @@
import React from 'react';
import React, { useContext } from 'react';
import { GamesContext } from '../../../context/games';
export default function Cancel() {
const games = useContext(GamesContext);
return <button className='Cancel'>Cancel</button>
const selectedGame = games.findGame({ uuid: games.proposal.selectedUUID });
if (selectedGame?.status === 'GAME_PROPOSAL_WAIT_FOR_OPPONENT')
return (
<button className='Cancel'>
Cancel
</button>
)
}

View File

@ -1,6 +1,15 @@
import React from 'react';
import React, { useContext } from 'react';
import { GamesContext } from '../../../context/games';
export default function Reject() {
const games = useContext(GamesContext);
return <button className='Reject'>Reject</button>
}
const selectedGame = games.findGame({ uuid: games.proposal.selectedUUID });
if (selectedGame?.status !== 'GAME_PROPOSAL_WAIT_FOR_OPPONENT')
return (
<button className='Reject'>
Reject
</button>
)
}

View File

@ -7,8 +7,6 @@ import Loading from '../../../components/Loading';
import Counter from '../../../components/Counter';
export default function GameSelector({ yours, opponents, isSelected, onSelect }) {
const games = useContext(GamesContext);
const gamesList = useContext(GamesContext).gamesList;
if (gamesList === null)
return <Loading />

View File

@ -17,6 +17,8 @@ const initialState = {
// Network
isPollingGamesList: false,
isPushingNewGame: false,
findGame,
};
function reducer(state, action) {
@ -44,4 +46,8 @@ function reducer(state, action) {
export default function useGamesReducer() {
return useReducer(reducer, initialState);
}
function findGame({uuid}) {
return this.gamesList?.find((game) => game.uuid === uuid);
}