chg: dev: massive refactor on front-end for unification and readiness #8
This commit is contained in:
@@ -112,3 +112,21 @@ export const useLobbyDataProvider = () => {
|
||||
};
|
||||
|
||||
export default useGameDataProvider;
|
||||
|
||||
/**
|
||||
* Profile Data Provider Hook
|
||||
* Centralized API communication layer for profile-related mutations
|
||||
*/
|
||||
export const useProfileDataProvider = () => {
|
||||
const uploadAvatarMutation = useMutation({
|
||||
mutationFn: ({ uploadUrl, file }) => {
|
||||
const fd = new FormData();
|
||||
fd.append('avatar', file);
|
||||
return fetch(uploadUrl, { method: 'POST', body: fd })
|
||||
.then(r => r.json())
|
||||
.then(data => { if (data.error) throw new Error(data.error); return data; });
|
||||
},
|
||||
});
|
||||
|
||||
return { uploadAvatarMutation };
|
||||
};
|
||||
|
||||
@@ -10,9 +10,8 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { useGame } from '@mine-contexts';
|
||||
import { DESC, IMAGES } from '@mine-utils';
|
||||
import useStepTimer from './useStepTimer';
|
||||
import useGameDataProvider from './useGameDataProvider';
|
||||
import { ChallengeCountdown, WaitingOverlayContent } from '@mine-components';
|
||||
import { useGameDataProvider, useStepTimer } from '@mine-hooks';
|
||||
|
||||
const useServerCommunication = (gameAssoc, gameInherited, opponentName, isEnvDev) => {
|
||||
const {
|
||||
|
||||
@@ -10,24 +10,18 @@
|
||||
import { useRef } from 'react';
|
||||
|
||||
const useStepTimer = () => {
|
||||
// Record when the current turn started (timestamp)
|
||||
const turnStartTimeRef = useRef(null);
|
||||
// Flag to track if we've already recorded a turn start
|
||||
const turnStartedRef = useRef(false);
|
||||
|
||||
const getStepElapsed = (currentActivePlayer, isGameRunning) => {
|
||||
// If game not running, return 0
|
||||
if (!isGameRunning) return 0;
|
||||
|
||||
// Only initialize the turn timer ONCE per call to getStepElapsed
|
||||
// This prevents resetting on multiple calls
|
||||
if (!turnStartedRef.current) {
|
||||
turnStartTimeRef.current = Date.now();
|
||||
turnStartedRef.current = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// After initialization, just calculate elapsed time
|
||||
if (turnStartTimeRef.current) {
|
||||
return Math.floor((Date.now() - turnStartTimeRef.current) / 1000);
|
||||
}
|
||||
@@ -40,7 +34,6 @@ const useStepTimer = () => {
|
||||
turnStartedRef.current = false;
|
||||
};
|
||||
|
||||
// Call this when we know a turn has actually changed (from server response)
|
||||
const startNewTurn = () => {
|
||||
turnStartTimeRef.current = Date.now();
|
||||
turnStartedRef.current = true;
|
||||
|
||||
Reference in New Issue
Block a user