no chatting in the archives!

This commit is contained in:
djmil 2023-11-15 18:33:18 +01:00
parent 6343f70851
commit 392e7e9251
2 changed files with 20 additions and 10 deletions

View File

@ -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) => {

View File

@ -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: