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 [value, setValue] = useState('');
const syncTimeoutRef = useRef(null); 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 if (syncTimeoutRef.current === null) { // <<--- Absorb external value ONLY if there is no scheduled sync
var externalValue = ''; var externalValue = '';
if (matchPath('/games/new', pathname)) if (matchPath('/games/new', pathname))
externalValue = games.newGame.message2opponent; externalValue = games.newGame.message2opponent;
else else if (matchPath('/games/proposal', pathname))
if (matchPath('/games/proposal', pathname))
externalValue = games.proposal.message2opponent; externalValue = games.proposal.message2opponent;
else if (matchPath('/games/active', pathname))
externalValue = games.active.message2opponent;
if (value !== externalValue) if (value !== externalValue)
setValue(externalValue); setValue(externalValue);
} }
@ -27,12 +34,15 @@ export default function Message2Opponent({ dispatchGames }) {
syncTimeoutRef.current = null; syncTimeoutRef.current = null;
if (matchPath('/games/new', pathname)) if (matchPath('/games/new', pathname))
dispatchGames({ type: 'nextNewGame', message2opponent }); return dispatchGames({ type: 'nextNewGame', message2opponent });
else
if (matchPath('/games/proposal', pathname)) if (matchPath('/games/proposal', pathname))
dispatchGames({ type: 'nextProposal', message2opponent }); return dispatchGames({ type: 'nextProposal', message2opponent });
else
console.warn('unknown path'); if (matchPath('/games/active', pathname))
return dispatchGames({ type: 'nextActive', message2opponent });
console.warn('unknown path');
} }
const update = (value) => { const update = (value) => {

View File

@ -54,13 +54,13 @@ function reducer(state, action) {
case 'nextActive': case 'nextActive':
return { return {
...state, ...state,
proposal: nextState(state.proposal, action) active: nextState(state.active, action)
}; };
case 'nextArchive': case 'nextArchive':
return { return {
...state, ...state,
proposal: nextState(state.proposal, action) archive: nextState(state.archive, action)
}; };
default: default: