diff --git a/webapp/src/container/Games.jsx b/webapp/src/container/Games.jsx index 43da121..595c98b 100644 --- a/webapp/src/container/Games.jsx +++ b/webapp/src/container/Games.jsx @@ -29,7 +29,7 @@ export default function Games({ context: { games, dispatchGames, gamesApi }, pla
- + {/* @@ -80,11 +80,14 @@ function ViewProvider({ players, dispatchGames }) { ) } -function ActionPanel() { +function ActionPanel({ players }) { return (
- } /> + + } /> , , ]} /> , , ]} /> , ]} /> diff --git a/webapp/src/container/games/action/Create.jsx b/webapp/src/container/games/action/Create.jsx index 2cee6c6..d29f925 100644 --- a/webapp/src/container/games/action/Create.jsx +++ b/webapp/src/container/games/action/Create.jsx @@ -1,6 +1,44 @@ -import React from 'react'; +import React, { useContext } from 'react'; +import { GamesContext } from '../../../context/games'; +import Wobler from '../../../components/Wobler'; -export default function Create() { - return + +export default function Create({ isCurrentUser }) { + const newGameCtx = useContext(GamesContext).newGame; + + const hasPlayers = checkPlayers(newGameCtx); + const hasCurrentUser = checkCurrentUser(newGameCtx, isCurrentUser); + + const pushNewGame = () => { + if (!hasPlayers) + return alert("Black and White players must be selected for the game"); + + if (!hasCurrentUser) + return alert("You must be one of the selected players"); + + if (newGameCtx.pushing) + return; // current request is still being processed + + console.log("send request"); + } + + return ( + + ) } + +function checkPlayers({ whitePlayer, blackPlayer }) { + return whitePlayer && blackPlayer + && whitePlayer !== blackPlayer; +} + +function checkCurrentUser({ whitePlayer, blackPlayer }, isCurrentUser) { + return isCurrentUser(whitePlayer) || isCurrentUser(blackPlayer); +} \ No newline at end of file