diff --git a/webapp/src/api/games.js b/webapp/src/api/games.js index 4d45ce8..dc8ee8c 100644 --- a/webapp/src/api/games.js +++ b/webapp/src/api/games.js @@ -1,5 +1,6 @@ import { usePolling, doPushing } from '../hook/api'; import { gamesInitialState } from '../reducer/games'; +import { Color } from '../components/Checkers'; export default function useGamesApi(gamesReducer, config) { const [games, dispatchGames] = gamesReducer; @@ -20,8 +21,8 @@ export default function useGamesApi(gamesReducer, config) { return { pollGamesList: usePollingGamesList, - pushNewGame: ({ opponentName, opponentColor, board, message }) => ifNot(games.isPushingNewGame) && - doPushing('/api/gameproposal', 'POST', { opponentName, opponentColor, board, message }, { + pushNewGame: ({ opponentName, myColor, board, message }) => ifNot(games.isPushingNewGame) && + doPushing('/api/gameproposal', 'POST', { opponentName, opponentColor: Color.opposite(myColor), board, message }, { onPushing: (isPushingNewGame) => dispatchGames({ type: 'next', isPushingNewGame }), onSuccess: (game) => dispatchGames({ type: 'next', gamesList: [game, ...games.gamesList], newGame: gamesInitialState.newGame }) }), diff --git a/webapp/src/components/Checkers.css b/webapp/src/components/Checkers.css index 9dfa13e..99a8455 100644 --- a/webapp/src/components/Checkers.css +++ b/webapp/src/components/Checkers.css @@ -10,6 +10,10 @@ align-items: center; } +.Board.flip { + flex-direction: column-reverse; +} + .Tile { border: 1px solid #e4e4e4; float: left; diff --git a/webapp/src/components/Checkers.jsx b/webapp/src/components/Checkers.jsx index 52ed697..d7dddf3 100644 --- a/webapp/src/components/Checkers.jsx +++ b/webapp/src/components/Checkers.jsx @@ -83,7 +83,7 @@ export function Board({ game, onClick }) { ); } - return
+ return
diff --git a/webapp/src/container/Games.jsx b/webapp/src/container/Games.jsx index fd8d594..5ec55f0 100644 --- a/webapp/src/container/Games.jsx +++ b/webapp/src/container/Games.jsx @@ -59,7 +59,7 @@ function ViewProvider({ dispatchGames, players }) { dispatchGames({ type: 'nextNewGame', opponentName, opponentColor })} + dispatchGames({ type: 'nextNewGame', opponentName, myColor })} players={players} /> } /> diff --git a/webapp/src/container/games/ActionPanel.jsx b/webapp/src/container/games/ActionPanel.jsx index 5ad9865..c3eb254 100644 --- a/webapp/src/container/games/ActionPanel.jsx +++ b/webapp/src/container/games/ActionPanel.jsx @@ -8,17 +8,17 @@ import Wobler from '../../components/Wobler'; export function Create({ onClick }) { const games = useContext(GamesContext); - const hasOpponent = games.newGame.opponentName && games.newGame.opponentColor; + const hasPlayers = games.newGame.opponentName && games.newGame.myColor; const validateNewGame = () => { - if (!hasOpponent) + if (!hasPlayers) return alert("You have to select an opponent"); onClick(games.newGame); } return ( -
) -} - -function gameFrom(newGame) { - return { - myColor: Color.opposite(newGame.opponentColor), - opponentName: newGame.opponentName, - opponentColor: newGame.opponentColor, - board: newGame.board, - }; } \ No newline at end of file diff --git a/webapp/src/container/games/view/NewGame.jsx b/webapp/src/container/games/view/NewGame.jsx index 758f955..f0040af 100644 --- a/webapp/src/container/games/view/NewGame.jsx +++ b/webapp/src/container/games/view/NewGame.jsx @@ -5,16 +5,16 @@ import { GamesContext } from '../../../context/games'; import DropdownList from '../../../components/DropdownList'; import { Color, WhiteStone, BlackStone } from '../../../components/Checkers'; -export default function NewGame({ players, setOpponent }) { +export default function NewGame({ players, setPlayers }) { const games = useContext(GamesContext); const [whitePlayer, blackPlayer] = (() => { - if (games.newGame.opponentColor === Color.white) - return [games.newGame.opponentName, players.currentUser]; - - if (games.newGame.opponentColor === Color.black) + if (games.newGame.myColor === Color.white) return [players.currentUser, games.newGame.opponentName]; + if (games.newGame.myColor === Color.black) + return [games.newGame.opponentName, players.currentUser]; + return ['', '']; })(); // <<-- Execute! @@ -37,11 +37,11 @@ export default function NewGame({ players, setOpponent }) { /* * The Component */ - const onSelect = (name, color) => { + const onSelect = (name, myColor) => { if (players.isCurrentUser(name)) - setOpponent(games.newGame.opponentName, Color.opposite(color)); + setPlayers(games.newGame.opponentName, myColor); else - setOpponent(name, color); + setPlayers(name, Color.opposite(myColor)); } return ( diff --git a/webapp/src/reducer/games.js b/webapp/src/reducer/games.js index 71f20f7..4fb7eca 100644 --- a/webapp/src/reducer/games.js +++ b/webapp/src/reducer/games.js @@ -7,7 +7,7 @@ export const gamesInitialState = { newGame: { opponentName: '', - opponentColor: '', + myColor: '', board: defaultBoard, message: '', },