From 392e7e92513b103236663f5306d15820fa4c63f9 Mon Sep 17 00:00:00 2001 From: djmil Date: Wed, 15 Nov 2023 18:33:18 +0100 Subject: [PATCH] no chatting in the archives! --- .../src/container/games/Message2Opponent.jsx | 26 +++++++++++++------ webapp/src/reducer/games.js | 4 +-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/webapp/src/container/games/Message2Opponent.jsx b/webapp/src/container/games/Message2Opponent.jsx index d0acc76..e19e984 100644 --- a/webapp/src/container/games/Message2Opponent.jsx +++ b/webapp/src/container/games/Message2Opponent.jsx @@ -8,15 +8,22 @@ export default function Message2Opponent({ dispatchGames }) { const [value, setValue] = useState(''); const syncTimeoutRef = useRef(null); + if (matchPath('/games/archive', pathname)) + return; // Shhh.. no chatting in the archives! + + if (matchPath('/games/proposal', pathname)) + return; // TODO: Enable GameProposal messages, as soon as it has been supported by the server side + 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)) + else if (matchPath('/games/proposal', pathname)) externalValue = games.proposal.message2opponent; - + else if (matchPath('/games/active', pathname)) + externalValue = games.active.message2opponent; + if (value !== externalValue) setValue(externalValue); } @@ -27,12 +34,15 @@ export default function Message2Opponent({ dispatchGames }) { syncTimeoutRef.current = null; if (matchPath('/games/new', pathname)) - dispatchGames({ type: 'nextNewGame', message2opponent }); - else + return dispatchGames({ type: 'nextNewGame', message2opponent }); + if (matchPath('/games/proposal', pathname)) - dispatchGames({ type: 'nextProposal', message2opponent }); - else - console.warn('unknown path'); + return dispatchGames({ type: 'nextProposal', message2opponent }); + + if (matchPath('/games/active', pathname)) + return dispatchGames({ type: 'nextActive', message2opponent }); + + console.warn('unknown path'); } const update = (value) => { diff --git a/webapp/src/reducer/games.js b/webapp/src/reducer/games.js index 36d0071..c3b8d14 100644 --- a/webapp/src/reducer/games.js +++ b/webapp/src/reducer/games.js @@ -54,13 +54,13 @@ function reducer(state, action) { case 'nextActive': return { ...state, - proposal: nextState(state.proposal, action) + active: nextState(state.active, action) }; case 'nextArchive': return { ...state, - proposal: nextState(state.proposal, action) + archive: nextState(state.archive, action) }; default: