Traduction + alias + routing + refactoring

This commit is contained in:
Sebastien Riviere
2026-02-20 22:00:54 +01:00
parent 776bbcd723
commit 76ee9674de
50 changed files with 2978 additions and 1746 deletions

View File

@@ -0,0 +1,43 @@
// React
import { useState, useEffect, useMemo } from "react";
// Contexts
import { useAuth } from "@/contexts/authContext";
import { useTeam } from "@/contexts/teamContext";
// Constants
import { GAME_STATE, USER_STATE } from '@/constants';
import { getLocationAuthorization } from '@/services/tasks/backgroundLocation';
export const useUserState = () => {
const { loggedIn } = useAuth();
const { teamInfos, gameState } = useTeam();
const { captured } = teamInfos;
const [isLocationAuthorized, setIsLocationAuthorized] = useState(null);
useEffect(() => {
const checkLocationAuth = async () => {
const result = await getLocationAuthorization();
setIsLocationAuthorized(result);
};
checkLocationAuth();
}, []);
return useMemo(() => {
if (isLocationAuthorized == null) return USER_STATE.LOADING;
if (!isLocationAuthorized) return USER_STATE.NO_LOCATION;
if (!loggedIn) return USER_STATE.OFFLINE;
switch (gameState) {
case GAME_STATE.SETUP:
return USER_STATE.WAITING;
case GAME_STATE.PLACEMENT:
return USER_STATE.PLACEMENT;
case GAME_STATE.PLAYING:
return captured ? USER_STATE.CAPTURED : USER_STATE.PLAYING;
case GAME_STATE.FINISHED:
return USER_STATE.FINISHED;
default:
return USER_STATE.WAITING;
}
}, [loggedIn, gameState, captured, isLocationAuthorized]);
};