From 9c8e2966843e71e5a2066602333cc3f66c71c50c Mon Sep 17 00:00:00 2001 From: djmil Date: Wed, 15 Nov 2023 09:15:38 +0100 Subject: [PATCH] GameProposal: Cancel show button only if cancelable game is selected --- webapp/src/container/games/action/Accept.jsx | 15 ++++++++++++--- webapp/src/container/games/action/Cancel.jsx | 13 +++++++++++-- webapp/src/container/games/action/Reject.jsx | 15 ++++++++++++--- webapp/src/container/games/view/GameSelector.jsx | 2 -- webapp/src/reducer/games.js | 6 ++++++ 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/webapp/src/container/games/action/Accept.jsx b/webapp/src/container/games/action/Accept.jsx index 5fba232..7a27b17 100644 --- a/webapp/src/container/games/action/Accept.jsx +++ b/webapp/src/container/games/action/Accept.jsx @@ -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 -} + const selectedGame = games.findGame({ uuid: games.proposal.selectedUUID }); + + if (selectedGame?.status !== 'GAME_PROPOSAL_WAIT_FOR_OPPONENT') + return ( + + ) +} \ No newline at end of file diff --git a/webapp/src/container/games/action/Cancel.jsx b/webapp/src/container/games/action/Cancel.jsx index 3d6642e..7686bf0 100644 --- a/webapp/src/container/games/action/Cancel.jsx +++ b/webapp/src/container/games/action/Cancel.jsx @@ -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 + const selectedGame = games.findGame({ uuid: games.proposal.selectedUUID }); + + if (selectedGame?.status === 'GAME_PROPOSAL_WAIT_FOR_OPPONENT') + return ( + + ) } diff --git a/webapp/src/container/games/action/Reject.jsx b/webapp/src/container/games/action/Reject.jsx index 4cc20ba..c8672d9 100644 --- a/webapp/src/container/games/action/Reject.jsx +++ b/webapp/src/container/games/action/Reject.jsx @@ -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 -} + const selectedGame = games.findGame({ uuid: games.proposal.selectedUUID }); + + if (selectedGame?.status !== 'GAME_PROPOSAL_WAIT_FOR_OPPONENT') + return ( + + ) +} \ No newline at end of file diff --git a/webapp/src/container/games/view/GameSelector.jsx b/webapp/src/container/games/view/GameSelector.jsx index c0faf9b..a105e9a 100644 --- a/webapp/src/container/games/view/GameSelector.jsx +++ b/webapp/src/container/games/view/GameSelector.jsx @@ -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 diff --git a/webapp/src/reducer/games.js b/webapp/src/reducer/games.js index c01feee..50a1add 100644 --- a/webapp/src/reducer/games.js +++ b/webapp/src/reducer/games.js @@ -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); } \ No newline at end of file