chg: pkg: upgrade all front-end packages to the latest available version - and fix all eslint warnings & errors #7
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
const CAPTCHA_STORAGE_KEY = 'mineseeker_captcha_verified';
|
||||
const CAPTCHA_TOKEN_KEY = 'mineseeker_captcha_token';
|
||||
@@ -46,9 +46,9 @@ const CaptchaOverlay = ({ siteKey, onVerified, children }) => {
|
||||
});
|
||||
});
|
||||
}
|
||||
}, [siteKey, onVerified]);
|
||||
}, [siteKey, onVerified, handleToken]);
|
||||
|
||||
const handleToken = token => {
|
||||
const handleToken = useCallback(token => {
|
||||
const wrapper = document.getElementById('mine-wrapper');
|
||||
if (wrapper) {
|
||||
wrapper.dataset.captchaToken = token;
|
||||
@@ -57,7 +57,7 @@ const CaptchaOverlay = ({ siteKey, onVerified, children }) => {
|
||||
sessionStorage.setItem(CAPTCHA_STORAGE_KEY, Date.now().toString());
|
||||
setVerified(true);
|
||||
onVerified?.();
|
||||
};
|
||||
}, [onVerified]);
|
||||
|
||||
const handleClick = () => {
|
||||
setLoading(true);
|
||||
|
||||
@@ -33,14 +33,12 @@ const GameTimer = () => {
|
||||
const timerIntervalRef = useRef(null);
|
||||
const gameStartedRef = useRef(false);
|
||||
|
||||
// Use timestamps instead of counters for more reliable background tracking
|
||||
const redStartTimeRef = useRef(null);
|
||||
const blueStartTimeRef = useRef(null);
|
||||
const lastActivePlayerRef = useRef(null);
|
||||
const pausedRedTimeRef = useRef(0);
|
||||
const pausedBlueTimeRef = useRef(0);
|
||||
|
||||
// Start timer when overlay is hidden (both players connected and game started)
|
||||
useEffect(() => {
|
||||
if (!overlay && !gameStartedRef.current) {
|
||||
gameStartedRef.current = true;
|
||||
@@ -53,28 +51,24 @@ const GameTimer = () => {
|
||||
pausedBlueTimeRef.current = 0;
|
||||
lastActivePlayerRef.current = activePlayer;
|
||||
}
|
||||
}, [overlay]);
|
||||
}, [activePlayer, overlay]);
|
||||
|
||||
// Stop timer on game end (resign/win)
|
||||
useEffect(() => {
|
||||
if (endRef.current) {
|
||||
setIsRunning(false);
|
||||
}
|
||||
}, [endRef.current]);
|
||||
}, [endRef]);
|
||||
|
||||
// Stop timer on connection loss
|
||||
useEffect(() => {
|
||||
if (connectionLost) {
|
||||
setIsRunning(false);
|
||||
}
|
||||
}, [connectionLost]);
|
||||
|
||||
// Handle player switch - pause one timer, resume the other
|
||||
useEffect(() => {
|
||||
if (!isRunning) return;
|
||||
|
||||
if (lastActivePlayerRef.current !== activePlayer) {
|
||||
// Player switched, save current accumulated time for whoever was active
|
||||
const startRef = lastActivePlayerRef.current ? blueStartTimeRef.current : redStartTimeRef.current;
|
||||
if (startRef) {
|
||||
const elapsed = Math.floor((Date.now() - startRef) / 1000);
|
||||
@@ -85,7 +79,6 @@ const GameTimer = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Start the new active player's timer
|
||||
if (activePlayer) {
|
||||
blueStartTimeRef.current = Date.now();
|
||||
} else {
|
||||
@@ -96,7 +89,6 @@ const GameTimer = () => {
|
||||
}
|
||||
}, [activePlayer, isRunning]);
|
||||
|
||||
// Main timer effect - update display every 100ms
|
||||
useEffect(() => {
|
||||
if (!isRunning) {
|
||||
if (timerIntervalRef.current) {
|
||||
@@ -109,7 +101,6 @@ const GameTimer = () => {
|
||||
let currentRedTime = pausedRedTimeRef.current;
|
||||
let currentBlueTime = pausedBlueTimeRef.current;
|
||||
|
||||
// Add elapsed time for the active player
|
||||
if (!activePlayer && redStartTimeRef.current) {
|
||||
currentRedTime += Math.floor((Date.now() - redStartTimeRef.current) / 1000);
|
||||
} else if (activePlayer && blueStartTimeRef.current) {
|
||||
@@ -127,10 +118,8 @@ const GameTimer = () => {
|
||||
};
|
||||
}, [isRunning, activePlayer]);
|
||||
|
||||
// Handle focus/blur to synchronize timer when tab regains focus
|
||||
useEffect(() => {
|
||||
const handleFocus = () => {
|
||||
// Force update when tab regains focus to sync any background drift
|
||||
if (isRunning) {
|
||||
let currentRedTime = pausedRedTimeRef.current;
|
||||
let currentBlueTime = pausedBlueTimeRef.current;
|
||||
@@ -150,7 +139,6 @@ const GameTimer = () => {
|
||||
return () => window.removeEventListener('focus', handleFocus);
|
||||
}, [isRunning, activePlayer]);
|
||||
|
||||
// Cleanup on unmount
|
||||
useEffect(() => () => {
|
||||
if (timerIntervalRef.current) {
|
||||
clearInterval(timerIntervalRef.current);
|
||||
|
||||
Reference in New Issue
Block a user