From 6dea7ae63fb3e99028addfebb70f17de86e05533 Mon Sep 17 00:00:00 2001 From: djmil Date: Wed, 15 Nov 2023 08:25:37 +0100 Subject: [PATCH] GameSekector: isSelected, onSelect --- webapp/src/container/Games.jsx | 9 ++++---- .../src/container/games/view/GameSelector.css | 21 ++++++++++------- .../src/container/games/view/GameSelector.jsx | 23 +++++++++++++------ webapp/src/reducer/games.js | 10 ++++++++ 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/webapp/src/container/Games.jsx b/webapp/src/container/Games.jsx index 66d93b8..aada860 100644 --- a/webapp/src/container/Games.jsx +++ b/webapp/src/container/Games.jsx @@ -58,7 +58,7 @@ function ViewSelector({ games }) { } function ViewProvider({ gamesReducer, players }) { - const [/*games*/, dispatchGames] = gamesReducer; + const [games, dispatchGames] = gamesReducer; return (
@@ -66,9 +66,7 @@ function ViewProvider({ gamesReducer, players }) { { - dispatchGames({ type: 'nextNewGame', whitePlayer, blackPlayer }) - }} + onSelectPlayer={(whitePlayer, blackPlayer) => dispatchGames({ type: 'nextNewGame', whitePlayer, blackPlayer })} players={players} /> } /> @@ -77,7 +75,8 @@ function ViewProvider({ gamesReducer, players }) { console.log("GameProposal", uuid)} + isSelected={(uuid) => uuid === games.proposal.selectedUUID} + onSelect={(selectedUUID) => dispatchGames({ type: 'nextProposal', selectedUUID })} /> } /> diff --git a/webapp/src/container/games/view/GameSelector.css b/webapp/src/container/games/view/GameSelector.css index 592ed6b..fc8d7eb 100644 --- a/webapp/src/container/games/view/GameSelector.css +++ b/webapp/src/container/games/view/GameSelector.css @@ -13,6 +13,13 @@ hr { margin-top: 3px; } +.Selectable .Title { + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; +} + .Selectable q { color: gray; font-size: 70%; @@ -33,9 +40,14 @@ hr { .Selectable:hover { background-color: #d3d3d360; border-radius: 2px; - } +.Selectable.selected { + background-color: #d3d3d3f0; + border-radius: 2px; +} + + .Separator { /* width: 20%; */ /* height: 20px; */ @@ -48,11 +60,4 @@ hr { .Separator .Counter { background-color: darkgray; -} - -.Selectable .Title { - display: flex; - flex-direction: row; - align-items: center; - justify-content: center; } \ 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 11a33f4..c0faf9b 100644 --- a/webapp/src/container/games/view/GameSelector.jsx +++ b/webapp/src/container/games/view/GameSelector.jsx @@ -6,20 +6,28 @@ import { Color, Player } from '../../../components/Checkers'; import Loading from '../../../components/Loading'; import Counter from '../../../components/Counter'; -export default function GameSelector({ yours, opponents, onClick }) { +export default function GameSelector({ yours, opponents, isSelected, onSelect }) { + const games = useContext(GamesContext); const gamesList = useContext(GamesContext).gamesList; if (gamesList === null) return + const onClick = (uuid) => { + if (isSelected(uuid)) + onSelect(null); // deselect previously selected game + else + onSelect(uuid); + } + const yoursList = gamesList.filter(game => game.status === yours) - .map(game => ) + .map(game => ) const opponentsList = gamesList.filter(game => game.status === opponents) - .map(game => ) + .map(game => ) return ( -
+
{yoursList} {opponentsList.length > 0 && } {opponentsList} @@ -27,14 +35,15 @@ export default function GameSelector({ yours, opponents, onClick }) { ) } -function Selectable({ game, onClick }) { +function Selectable({ game, selected, onClick }) { const myColor = game.myColor; const opponentColor = Color.opposite(myColor); const opponentName = game.opponentName; return (
-
onClick(game.uuid)}> +
onClick(game.uuid)}>
vs @@ -49,7 +58,7 @@ function Selectable({ game, onClick }) { function Separator({ counter }) { return ( -
+
waiting for opponent
diff --git a/webapp/src/reducer/games.js b/webapp/src/reducer/games.js index 74ea624..c01feee 100644 --- a/webapp/src/reducer/games.js +++ b/webapp/src/reducer/games.js @@ -10,6 +10,10 @@ const initialState = { message2opponent: '', }, + proposal: { + selectedUUID: null, + }, + // Network isPollingGamesList: false, isPushingNewGame: false, @@ -27,6 +31,12 @@ function reducer(state, action) { newGame: nextState(state.newGame, action) }; + case 'nextProposal': + return { + ...state, + proposal: nextState(state.proposal, action) + }; + default: throw Error('GamesReducer: unknown action.type', action.type); }