new: usr: add timer for the acceptance of the challenge #4
This commit is contained in:
@@ -14,7 +14,8 @@ import { DESC } from '@mine-utils';
|
||||
import useStepTimer from './useStepTimer';
|
||||
import { WaitingOverlayContent } from '@mine-components';
|
||||
|
||||
/** Handles all server communication: SSE (Mercure), REST calls, and the initialization lifecycle. */
|
||||
import { ChallengeCountdown } from '@mine-components';
|
||||
|
||||
const useServerCommunication = (gameAssoc, gameInherited, isEnvDev) => {
|
||||
const {
|
||||
/** Async-safe refs */
|
||||
@@ -136,8 +137,10 @@ const useServerCommunication = (gameAssoc, gameInherited, isEnvDev) => {
|
||||
|
||||
const wChallenge = payload => {
|
||||
const { challengerName, challengerGameAssoc } = payload;
|
||||
let declineTimeout = null;
|
||||
|
||||
const handleAccept = () => {
|
||||
clearTimeout(declineTimeout);
|
||||
fetch('/api/game/challenge/respond/' + challengerGameAssoc, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
@@ -148,6 +151,7 @@ const useServerCommunication = (gameAssoc, gameInherited, isEnvDev) => {
|
||||
};
|
||||
|
||||
const handleDecline = () => {
|
||||
clearTimeout(declineTimeout);
|
||||
fetch('/api/game/challenge/respond/' + challengerGameAssoc, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
@@ -162,12 +166,11 @@ const useServerCommunication = (gameAssoc, gameInherited, isEnvDev) => {
|
||||
}).catch(() => {});
|
||||
};
|
||||
|
||||
declineTimeout = setTimeout(handleDecline, 30000);
|
||||
|
||||
showOverlay(
|
||||
challengerName + ' wants to challenge you!',
|
||||
<div className="resign">
|
||||
<a onClick={handleAccept}>Accept</a>
|
||||
<a onClick={handleDecline}>Decline</a>
|
||||
</div>,
|
||||
<ChallengeCountdown onAccept={handleAccept} onDecline={handleDecline} />,
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user