From cbc78dfcf1071bfe3320e42da8155e21d5a9f63a Mon Sep 17 00:00:00 2001 From: djmil Date: Wed, 15 Nov 2023 09:36:23 +0100 Subject: [PATCH] message2opponent works proposals but does nothing in reality sicne no actual message is being included in request --- .../src/container/games/Message2Opponent.jsx | 27 ++++++++++++------- webapp/src/reducer/games.js | 1 + 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/webapp/src/container/games/Message2Opponent.jsx b/webapp/src/container/games/Message2Opponent.jsx index 21dca32..d0acc76 100644 --- a/webapp/src/container/games/Message2Opponent.jsx +++ b/webapp/src/container/games/Message2Opponent.jsx @@ -8,13 +8,17 @@ export default function Message2Opponent({ dispatchGames }) { const [value, setValue] = useState(''); const syncTimeoutRef = useRef(null); - if (syncTimeoutRef.current === null) { // <<--- Absorb external value if there is no scheduled sync - if (matchPath('/games/new', pathname)) { - if (value !== games.newGame.message2opponent) - setValue(games.newGame.message2opponent); - } else if (value !== '') { - setValue(''); - } + if (syncTimeoutRef.current === null) { // <<--- Absorb external value ONLY if there is no scheduled sync + var externalValue = ''; + + if (matchPath('/games/new', pathname)) + externalValue = games.newGame.message2opponent; + else + if (matchPath('/games/proposal', pathname)) + externalValue = games.proposal.message2opponent; + + if (value !== externalValue) + setValue(externalValue); } /* --- */ @@ -23,9 +27,12 @@ export default function Message2Opponent({ dispatchGames }) { syncTimeoutRef.current = null; if (matchPath('/games/new', pathname)) - return dispatchGames({ type: 'nextNewGame', message2opponent }); - - console.warn('unknown path'); + dispatchGames({ type: 'nextNewGame', message2opponent }); + else + if (matchPath('/games/proposal', pathname)) + dispatchGames({ type: 'nextProposal', message2opponent }); + else + console.warn('unknown path'); } const update = (value) => { diff --git a/webapp/src/reducer/games.js b/webapp/src/reducer/games.js index 50a1add..4b083c5 100644 --- a/webapp/src/reducer/games.js +++ b/webapp/src/reducer/games.js @@ -12,6 +12,7 @@ const initialState = { proposal: { selectedUUID: null, + message2opponent: '', }, // Network