mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-04-10 16:30:18 +02:00
Server heavy refactoring 4 (not functionnal)
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
module.exports = {
|
||||
"env": {
|
||||
"es2021": true,
|
||||
"node": true,
|
||||
"react-native/react-native": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:react/recommended",
|
||||
"plugin:react-hooks/recommended",
|
||||
"plugin:import/recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaFeatures": {
|
||||
"jsx": true
|
||||
},
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"react",
|
||||
"react-native"
|
||||
],
|
||||
"ignorePatterns": [
|
||||
"android/",
|
||||
".expo/",
|
||||
"node_modules/",
|
||||
"src/assets/",
|
||||
],
|
||||
"rules": {
|
||||
"react/react-in-jsx-scope": "off",
|
||||
"react/prop-types": "off",
|
||||
"no-unused-vars": "warn",
|
||||
"semi": ["error", "always"],
|
||||
"react-native/no-unused-styles": "warn",
|
||||
"react-native/no-single-element-style-arrays": "warn",
|
||||
'import/extensions': 'off',
|
||||
"import/no-unresolved": "off",
|
||||
"import/named": "off",
|
||||
"import/namespace": "off",
|
||||
"import/default": "off",
|
||||
"import/no-named-as-default-member": "off"
|
||||
},
|
||||
"settings": {
|
||||
"react": {
|
||||
"version": "detect"
|
||||
},
|
||||
"import/ignore": [
|
||||
"react-native"
|
||||
],
|
||||
'import/resolver': {
|
||||
"node": {
|
||||
"extensions": ['.js', '.jsx', '.ts', '.tsx'],
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
@@ -9,13 +9,12 @@ import { useTeam } from '@/contexts/teamContext';
|
||||
// Components
|
||||
import { IconButton } from '@/components/common/IconButton';
|
||||
// Constants
|
||||
import { COLORS } from '@/constants';
|
||||
import { COLORS } from '@/config';
|
||||
|
||||
const GameLayout = () => {
|
||||
const { t, i18n } = useTranslation();
|
||||
const { logout } = useAuth();
|
||||
const { teamInfos } = useTeam();
|
||||
const { name } = teamInfos;
|
||||
const { teamName } = useTeam();
|
||||
|
||||
const toggleLanguage = () => {
|
||||
i18n.changeLanguage(i18n.language === 'fr' ? 'en' : 'fr');
|
||||
@@ -31,13 +30,11 @@ const GameLayout = () => {
|
||||
}
|
||||
};
|
||||
|
||||
formatText("les minions du bds qui gagne");
|
||||
|
||||
return (
|
||||
<View style={styles.globalContainer}>
|
||||
<View style={styles.headerContainer}>
|
||||
<IconButton style={styles.logoutIcon} source={require('@/assets/images/logout.png')} onPress={logout} />
|
||||
<Text style={styles.name} numberOfLines={1} adjustsFontSizeToFit>{formatText(name, 22)}</Text>
|
||||
<Text style={styles.name} numberOfLines={1} adjustsFontSizeToFit>{formatText(teamName, 22)}</Text>
|
||||
<IconButton style={styles.traductionIcon} source={require('@/assets/images/language.png')} onPress={toggleLanguage} />
|
||||
</View>
|
||||
<Slot/>
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
import { Text, StyleSheet, ScrollView } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
// Components
|
||||
import { TeamStats } from '@/components/game/TeamStats';
|
||||
import { Show } from '@/components/common/Show';
|
||||
// Hook
|
||||
import { useUserState } from '@/hooks/useUserState';
|
||||
// Constants
|
||||
import { USER_STATE } from '@/constants';
|
||||
import { USER_STATE } from '@/config';
|
||||
|
||||
/*
|
||||
const Leaderboard = ({ teams }) => {
|
||||
@@ -91,7 +90,6 @@ const End = () => {
|
||||
<Text style={styles.title}>{t("end.title_win")}</Text>
|
||||
</Show>
|
||||
<Text style={styles.subtitle}>{t("end.paragraph")}</Text>
|
||||
<TeamStats/>
|
||||
</ScrollView>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -17,14 +17,14 @@ import { useTeam } from '@/contexts/teamContext';
|
||||
// Hooks
|
||||
import { useUserState } from '@/hooks/useUserState';
|
||||
// Services
|
||||
import { emitSendPosition } from '@/services/socket/emitters';
|
||||
import { emitLocation } from '@/services/socket/emitters';
|
||||
// Constants
|
||||
import { USER_STATE } from '@/constants';
|
||||
import { USER_STATE } from '@/config';
|
||||
|
||||
const Play = () => {
|
||||
const { t } = useTranslation();
|
||||
const { teamInfos, nextZoneDate } = useTeam();
|
||||
const { locationSendDeadline, hasHandicap, enemyLocation, lastSentLocation } = teamInfos;
|
||||
const { teamStateData } = useTeam();
|
||||
const { zoneTransitionDate, scanDate, hasHandicap, scanLocation, targetScanLocation } = teamStateData;
|
||||
const userState = useUserState();
|
||||
const [bottomContainerHeight, setBottomContainerHeight] = useState(0);
|
||||
|
||||
@@ -35,8 +35,8 @@ const Play = () => {
|
||||
</Show>
|
||||
<Show when={userState == USER_STATE.PLAYING}>
|
||||
<View style={styles.timerContainer}>
|
||||
<TimerMMSS style={styles.timer} title={t("play.info.zone_reduction_label")} date={nextZoneDate} />
|
||||
<TimerMMSS style={styles.timer} title={t("play.info.send_position_label")} date={locationSendDeadline} />
|
||||
<TimerMMSS style={styles.timer} title={t("play.info.zone_reduction_label")} date={zoneTransitionDate} />
|
||||
<TimerMMSS style={styles.timer} title={t("play.info.send_position_label")} date={scanDate} />
|
||||
</View>
|
||||
</Show>
|
||||
<View style={styles.mapContainer} onLayout={(event) => setBottomContainerHeight(event.nativeEvent.layout.height)}>
|
||||
@@ -48,13 +48,13 @@ const Play = () => {
|
||||
<GameZone/>
|
||||
</Show>
|
||||
<Show when={userState == USER_STATE.PLAYING && !hasHandicap}>
|
||||
<PositionMarker position={lastSentLocation} color={"grey"} onPress={() => Alert.alert(t("play.map.previous_marker_title"), t("play.map.previous_marker_description"))} />
|
||||
<PositionMarker position={enemyLocation} color={"red"} onPress={() => Alert.alert(t("play.map.enemy_marker_title"), t("play.map.enemy_marker_description"))} />
|
||||
<PositionMarker position={scanLocation} color={"grey"} onPress={() => Alert.alert(t("play.map.previous_marker_title"), t("play.map.previous_marker_description"))} />
|
||||
<PositionMarker position={targetScanLocation} color={"red"} onPress={() => Alert.alert(t("play.map.enemy_marker_title"), t("play.map.enemy_marker_description"))} />
|
||||
</Show>
|
||||
</Map>
|
||||
<LinearGradient colors={['rgba(0,0,0,0.3)', 'rgba(0,0,0,0)']} style={styles.gradient}/>
|
||||
<Show when={userState == USER_STATE.PLAYING && !hasHandicap}>
|
||||
<IconButton style={styles.updatePosition} source={require("@/assets/images/update_position.png")} onPress={emitSendPosition} />
|
||||
<IconButton style={styles.updatePosition} source={require("@/assets/images/update_position.png")} onPress={emitLocation} />
|
||||
</Show>
|
||||
<Toasts/>
|
||||
</View>
|
||||
|
||||
@@ -11,7 +11,7 @@ import { useUserState } from '@/hooks/useUserState';
|
||||
// Services
|
||||
import { startLocationTracking , stopLocationTracking } from '@/services/tasks/backgroundLocation';
|
||||
// Constants
|
||||
import { USER_STATE, COLORS } from '@/constants';
|
||||
import { USER_STATE, COLORS } from '@/config';
|
||||
// Traduction
|
||||
import '@/i18n/config';
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
module.exports = function (api) {
|
||||
api.cache(true);
|
||||
return {
|
||||
presets: ['babel-preset-expo'],
|
||||
plugins: [
|
||||
[
|
||||
'module-resolver',
|
||||
{
|
||||
root: ['./'],
|
||||
alias: {
|
||||
'@': './src',
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
api.cache(true);
|
||||
return {
|
||||
presets: ['babel-preset-expo'],
|
||||
plugins: [
|
||||
[
|
||||
'module-resolver',
|
||||
{
|
||||
root: ['./'],
|
||||
alias: {
|
||||
'@': './src',
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
};
|
||||
|
||||
44
mobile/traque-app/eslint.config.mjs
Normal file
44
mobile/traque-app/eslint.config.mjs
Normal file
@@ -0,0 +1,44 @@
|
||||
import js from "@eslint/js";
|
||||
import globals from "globals";
|
||||
import reactPlugin from "eslint-plugin-react";
|
||||
import reactHooksPlugin from "eslint-plugin-react-hooks";
|
||||
|
||||
export default [
|
||||
{
|
||||
ignores: [".expo/*", "android/*", "ios/*", "keys/*", "node_modules/*", "src/assets/*", "babel.config.js"],
|
||||
},
|
||||
js.configs.recommended,
|
||||
{
|
||||
files: ["**/*.{js,jsx,mjs}"],
|
||||
plugins: {
|
||||
"react": reactPlugin,
|
||||
"react-hooks": reactHooksPlugin,
|
||||
},
|
||||
languageOptions: {
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
parserOptions: {
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
},
|
||||
},
|
||||
globals: {
|
||||
...globals.browser,
|
||||
...globals.node,
|
||||
},
|
||||
},
|
||||
settings: {
|
||||
react: {
|
||||
version: "detect",
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
...reactPlugin.configs.recommended.rules,
|
||||
...reactHooksPlugin.configs.recommended.rules,
|
||||
"react/react-in-jsx-scope": "off",
|
||||
"react/prop-types": "off",
|
||||
"semi": ["error", "always"],
|
||||
"no-unused-vars": "warn",
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -1,13 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": { "@/*": ["src/*"] },
|
||||
"jsx": "react-native",
|
||||
"checkJs": true,
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {"@/*": ["src/*"]},
|
||||
"jsx": "react-native",
|
||||
"checkJs": true,
|
||||
},
|
||||
"include": ["src/**/*", "app.json", "assets.d.ts"],
|
||||
"exclude": ["node_modules", ".expo", "android", "ios"],
|
||||
}
|
||||
|
||||
28438
mobile/traque-app/package-lock.json
generated
28438
mobile/traque-app/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -13,7 +13,6 @@
|
||||
"@react-native-async-storage/async-storage": "1.23.1",
|
||||
"@react-navigation/native": "^7.0.14",
|
||||
"@react-navigation/stack": "^7.1.1",
|
||||
"axxios": "^0.1.0",
|
||||
"babel-plugin-module-resolver": "^5.0.2",
|
||||
"expo": "~52.0.46",
|
||||
"expo-build-properties": "~0.13.3",
|
||||
@@ -34,7 +33,6 @@
|
||||
"react-native": "0.76.9",
|
||||
"react-native-collapsible": "^1.6.2",
|
||||
"react-native-device-info": "^14.0.4",
|
||||
"react-native-dotenv": "^3.4.11",
|
||||
"react-native-gesture-handler": "~2.20.2",
|
||||
"react-native-image-picker": "^4.0.6",
|
||||
"react-native-image-viewing": "^0.2.2",
|
||||
@@ -47,11 +45,12 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.0",
|
||||
"@eslint/js": "^9.39.4",
|
||||
"@react-native-community/cli": "latest",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
"eslint": "^9.39.4",
|
||||
"eslint-plugin-react": "^7.37.5",
|
||||
"eslint-plugin-react-native": "^5.0.0"
|
||||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"globals": "^17.4.0"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ScrollView, View, Image, StyleSheet, TouchableHighlight } from 'react-n
|
||||
import Collapsible from 'react-native-collapsible';
|
||||
import LinearGradient from 'react-native-linear-gradient';
|
||||
// Constants
|
||||
import { COLORS } from '@/constants';
|
||||
import { COLORS } from '@/config';
|
||||
|
||||
export const Drawer = ({ contentContainerStyle = {}, height, children }) => {
|
||||
const [collapsibleState, setCollapsibleState] = useState(true);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Show } from '@/components/common/Show';
|
||||
// Hook
|
||||
import { useLocation } from '@/hooks/useLocation';
|
||||
// Util
|
||||
import { INITIAL_REGIONS } from '@/constants';
|
||||
import { INITIAL_REGIONS } from '@/config';
|
||||
|
||||
export const Map = ({ children }) => {
|
||||
const { location } = useLocation();
|
||||
|
||||
@@ -1,30 +1,24 @@
|
||||
// React
|
||||
import { useMemo } from 'react';
|
||||
import { Circle, Polygon } from 'react-native-maps';
|
||||
import { Polygon } from 'react-native-maps';
|
||||
// Components
|
||||
import { DashedCircle, InvertedCircle, InvertedPolygon } from '@/components/common/Layers';
|
||||
// Contexts
|
||||
import { useTeam } from '@/contexts/teamContext';
|
||||
// Constants
|
||||
import { ZONE_TYPES } from '@/constants';
|
||||
import { ZONE_TYPES } from '@/config';
|
||||
|
||||
export const StartZone = () => {
|
||||
const { teamInfos } = useTeam();
|
||||
const { startingArea } = teamInfos;
|
||||
const { teamStateData } = useTeam();
|
||||
const { placementZone } = teamStateData;
|
||||
|
||||
return useMemo(() => {
|
||||
if (!startingArea) return null;
|
||||
if (!placementZone) return null;
|
||||
|
||||
return (
|
||||
<Circle
|
||||
center={{ latitude: startingArea.center.lat, longitude: startingArea.center.lng }}
|
||||
radius={startingArea.radius}
|
||||
strokeWidth={2}
|
||||
strokeColor={`rgba(0, 0, 255, 1)`}
|
||||
fillColor={`rgba(0, 0, 255, 0.2)`}
|
||||
/>
|
||||
<Polygon coordinates={placementZone} strokeWidth={2} strokeColor={`rgba(0, 0, 255, 1)`} fillColor={`rgba(0, 0, 255, 0.2)`} />
|
||||
);
|
||||
}, [startingArea]);
|
||||
}, [placementZone]);
|
||||
};
|
||||
|
||||
const latToLatitude = (pos) => ({latitude: pos.lat, longitude: pos.lng});
|
||||
|
||||
@@ -7,7 +7,6 @@ import { ExpandableImage } from '@/components/common/Image';
|
||||
import { CustomTextInput } from '@/components/common/Input';
|
||||
import { Drawer } from '@/components/common/Drawer';
|
||||
import { Show } from '@/components/common/Show';
|
||||
import { TeamStats } from '@/components/game/TeamStats';
|
||||
// Contexts
|
||||
import { useAuth } from '@/contexts/authContext';
|
||||
import { useTeam } from '@/contexts/teamContext';
|
||||
@@ -19,8 +18,8 @@ import { IconButton } from '../common/IconButton';
|
||||
export const TargetInfoDrawer = ({ height }) => {
|
||||
const { t } = useTranslation();
|
||||
const { teamId } = useAuth();
|
||||
const { teamInfos } = useTeam();
|
||||
const { enemyName, captureCode, name, hasHandicap } = teamInfos;
|
||||
const { teamName, teamStateData } = useTeam();
|
||||
const { targetName, captureCode, hasHandicap } = teamStateData;
|
||||
const [enemyCaptureCode, setEnemyCaptureCode] = useState("");
|
||||
const [isCapturing, setIsCapturing] = useState(false);
|
||||
|
||||
@@ -49,10 +48,10 @@ export const TargetInfoDrawer = ({ height }) => {
|
||||
|
||||
return (
|
||||
<Drawer contentContainerStyle={styles.drawer} height={height}>
|
||||
<Text style={styles.teamCode}>{t("play.drawer.capture_code", {name: name ?? t("common.no_value"), code: String(captureCode).padStart(4,"0")})}</Text>
|
||||
<Text style={styles.teamCode}>{t("play.drawer.capture_code", {name: teamName ?? t("common.no_value"), code: String(captureCode).padStart(4,"0")})}</Text>
|
||||
<Show when={!hasHandicap}>
|
||||
<View style={styles.targetContainer}>
|
||||
<Text style={styles.targetName}>{t("play.drawer.target_name", {name: enemyName ?? t("common.no_value")})}</Text>
|
||||
<Text style={styles.targetName}>{t("play.drawer.target_name", {name: targetName ?? t("common.no_value")})}</Text>
|
||||
<ExpandableImage source={enemyImage(teamId)}/>
|
||||
</View>
|
||||
<View style={styles.captureContainer}>
|
||||
@@ -60,7 +59,6 @@ export const TargetInfoDrawer = ({ height }) => {
|
||||
<IconButton style={styles.captureButton} source={require("@/assets/images/target/white.png")} onPress={handleCapture} />
|
||||
</View>
|
||||
</Show>
|
||||
<TeamStats/>
|
||||
</Drawer>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -22,8 +22,8 @@ const Stat = ({ children, source, description }) => {
|
||||
|
||||
export const TeamStats = () => {
|
||||
const { t } = useTranslation();
|
||||
const { teamInfos, startDate } = useTeam();
|
||||
const { distance, finishDate, nCaptures, nSentLocation } = teamInfos;
|
||||
const { teamInfos, startDate } = useTeam(); // TODO : outdated variables
|
||||
const { distance, finishDate, nCaptures, nSentLocation } = teamInfos; // TODO : outdated variables
|
||||
const timeSinceGameStart = useTimeSinceSeconds(startDate);
|
||||
|
||||
const avgSpeed = useMemo(() => {
|
||||
|
||||
@@ -8,40 +8,40 @@ import { useUserState } from '@/hooks/useUserState';
|
||||
// Util
|
||||
import { secondsToMMSS } from '@/utils/functions';
|
||||
// Constants
|
||||
import { USER_STATE } from '@/constants';
|
||||
import { USER_STATE } from '@/config';
|
||||
import { useCountdownSeconds } from '@/hooks/useTimeDelta';
|
||||
|
||||
export const Toasts = () => {
|
||||
const { t } = useTranslation();
|
||||
const { teamInfos } = useTeam();
|
||||
const { outOfZone, outOfZoneDeadline, hasHandicap, enemyHasHandicap, ready } = teamInfos;
|
||||
const { teamStateData } = useTeam();
|
||||
const { isOutOfZone, handicapDate, hasHandicap, targetHasHandicap, isInPlacementZone } = teamStateData;
|
||||
const userState = useUserState();
|
||||
const outOfZoneTimeLeft = useCountdownSeconds(outOfZoneDeadline);
|
||||
const outOfZoneTimeLeft = useCountdownSeconds(handicapDate);
|
||||
|
||||
const toastData = [
|
||||
{
|
||||
condition: userState === USER_STATE.PLACEMENT,
|
||||
id: 'placement',
|
||||
text: ready ? t("play.toast.placed") : t("play.toast.not_placed"),
|
||||
toastColor: ready ? "rgb(25, 165, 25)" : "rgb(204, 51, 51)" ,
|
||||
text: isInPlacementZone ? t("play.toast.placed") : t("play.toast.not_placed"),
|
||||
toastColor: isInPlacementZone ? "rgb(25, 165, 25)" : "rgb(204, 51, 51)" ,
|
||||
textColor: "white"
|
||||
},
|
||||
{
|
||||
condition: userState === USER_STATE.PLAYING && !outOfZone && enemyHasHandicap,
|
||||
condition: userState === USER_STATE.PLAYING && !isOutOfZone && targetHasHandicap,
|
||||
id: 'enemy_revealed',
|
||||
text: t("play.toast.enemy_position_revealed"),
|
||||
toastColor: "white",
|
||||
textColor: "black"
|
||||
},
|
||||
{
|
||||
condition: userState === USER_STATE.PLAYING && outOfZone && hasHandicap,
|
||||
condition: userState === USER_STATE.PLAYING && isOutOfZone && hasHandicap,
|
||||
id: 'out_of_zone',
|
||||
text: `${t("play.toast.go_in_zone")}\n${t("play.toast.team_position_revealed")}`,
|
||||
toastColor: "white",
|
||||
textColor: "black"
|
||||
},
|
||||
{
|
||||
condition: userState === USER_STATE.PLAYING && outOfZone && !hasHandicap,
|
||||
condition: userState === USER_STATE.PLAYING && isOutOfZone && !hasHandicap,
|
||||
id: 'has_handicap',
|
||||
text: `${t("play.toast.go_in_zone")}\n${t("play.toast.out_of_zone_message", {time: secondsToMMSS(outOfZoneTimeLeft)})}`,
|
||||
toastColor: "white",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from './config';
|
||||
export * from './server';
|
||||
export * from './game';
|
||||
export * from './map';
|
||||
export * from './colors';
|
||||
@@ -1,51 +1,45 @@
|
||||
// React
|
||||
import { createContext, useContext, useState, useEffect, useCallback, useMemo } from "react";
|
||||
import DeviceInfo from 'react-native-device-info';
|
||||
import { createContext, useContext, useState, useCallback, useMemo } from "react";
|
||||
// Hook
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
// Services
|
||||
import { emitLogin, emitLogout, emitBattery, emitDeviceInfo } from "@/services/socket/emitters";
|
||||
import { emitLogin, emitLogout } from "@/services/socket/emitters";
|
||||
|
||||
const AuthContext = createContext(null);
|
||||
|
||||
export const AuthProvider = ({ children }) => {
|
||||
const [loggedIn, setLoggedIn] = useState(false);
|
||||
const [teamId, setTeamId] = useLocalStorage("team_id", null);
|
||||
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
||||
const [savedTeamId, setSavedTeamId] = useLocalStorage("team_id", null);
|
||||
|
||||
const login = useCallback(async (password) => {
|
||||
if (loggedIn != false) return;
|
||||
|
||||
try {
|
||||
const response = await emitLogin(password);
|
||||
setLoggedIn(response.isLoggedIn);
|
||||
if (response.isLoggedIn) setTeamId(password);
|
||||
return response.isLoggedIn;
|
||||
} catch (error) {
|
||||
setLoggedIn(false);
|
||||
throw error;
|
||||
const login = useCallback(async (teamId) => {
|
||||
if (isLoggedIn) return;
|
||||
if (await emitLogin(teamId)) {
|
||||
setIsLoggedIn(true);
|
||||
setSavedTeamId(teamId);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, [loggedIn, setTeamId]);
|
||||
}, [isLoggedIn, setSavedTeamId]);
|
||||
|
||||
const logout = useCallback(() => {
|
||||
if (loggedIn != true) return;
|
||||
|
||||
setLoggedIn(false);
|
||||
setTeamId(null);
|
||||
if (!isLoggedIn) return;
|
||||
setIsLoggedIn(false);
|
||||
setSavedTeamId(null);
|
||||
emitLogout();
|
||||
}, [loggedIn, setTeamId]);
|
||||
}, [isLoggedIn, setSavedTeamId]);
|
||||
|
||||
/*
|
||||
// Try to log in with saved teamId
|
||||
// Try to log in with saved savedTeamId
|
||||
useEffect(() => {
|
||||
if (!loggedIn && teamId) {
|
||||
login(teamId);
|
||||
if (!isLoggedIn && savedTeamId) {
|
||||
login(savedTeamId);
|
||||
}
|
||||
}, [loggedIn, teamId, login]);
|
||||
*/
|
||||
}, [isLoggedIn, savedTeamId, login]);
|
||||
|
||||
// Emit battery level and phone model at log in
|
||||
useEffect(() => {
|
||||
if (!loggedIn) return;
|
||||
if (!isLoggedIn) return;
|
||||
|
||||
const sendInfo = async () => {
|
||||
const [brand, model, name] = await Promise.all([
|
||||
@@ -66,9 +60,10 @@ export const AuthProvider = ({ children }) => {
|
||||
const batteryCheckInterval = setInterval(() => sendBattery(), 5*60*1000); // 5 minutes
|
||||
|
||||
return () => clearInterval(batteryCheckInterval);
|
||||
}, [loggedIn]);
|
||||
}, [isLoggedIn]);
|
||||
*/
|
||||
|
||||
const value = useMemo(() => ({ teamId, loggedIn, login, logout}), [teamId, loggedIn, login, logout]);
|
||||
const value = useMemo(() => ({ savedTeamId, isLoggedIn, login, logout }), [savedTeamId, isLoggedIn, login, logout]);
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={value}>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useAuth } from "@/contexts/authContext";
|
||||
// Services
|
||||
import { socket } from "@/services/socket/connection";
|
||||
// Constants
|
||||
import { GAME_STATE } from "@/constants";
|
||||
import { GAME_STATE } from "@/config";
|
||||
|
||||
const TeamContext = createContext(null);
|
||||
|
||||
@@ -18,47 +18,25 @@ const useOnEvent = (event, callback) => {
|
||||
}, [event, callback]);
|
||||
};
|
||||
|
||||
export const TeamProvider = ({children}) => {
|
||||
export const TeamProvider = ({ children }) => {
|
||||
const { logout } = useAuth();
|
||||
// update_team
|
||||
const [teamInfos, setTeamInfos] = useState({});
|
||||
// game_state
|
||||
const [gameState, setGAME_STATE] = useState(GAME_STATE.SETUP);
|
||||
const [startDate, setStartDate] = useState(null);
|
||||
// current_zone
|
||||
const [zoneExtremities, setZoneExtremities] = useState(null);
|
||||
const [nextZoneDate, setNextZoneDate] = useState(null);
|
||||
// settings
|
||||
const [messages, setMessages] = useState(null);
|
||||
const [zoneType, setZoneType] = useState(null);
|
||||
const [teamId, setTeamId] = useState(null);
|
||||
const [teamName, setTeamName] = useState(null);
|
||||
const [gameState, setGameState] = useState(GAME_STATE.SETUP);
|
||||
const [teamStateData, setTeamStateData] = useState({});
|
||||
|
||||
useOnEvent("update_team", (data) => {
|
||||
setTeamInfos(teamInfos => ({...teamInfos, ...data}));
|
||||
});
|
||||
|
||||
useOnEvent("game_state", (data) => {
|
||||
setGAME_STATE(data.state);
|
||||
setStartDate(data.date);
|
||||
});
|
||||
|
||||
useOnEvent("settings", (data) => {
|
||||
setMessages(data.messages);
|
||||
setZoneType(data.zone.type);
|
||||
//TODO
|
||||
//setSendPositionDelay(data.sendPositionDelay);
|
||||
//setOutOfZoneDelay(data.outOfZoneDelay);
|
||||
});
|
||||
|
||||
useOnEvent("current_zone", (data) => {
|
||||
setZoneExtremities({begin: data.begin, end: data.end});
|
||||
setNextZoneDate(data.endDate);
|
||||
useOnEvent("update-full", ({ id, name, gameState, stateData }) => {
|
||||
setTeamId(id);
|
||||
setTeamName(name);
|
||||
setGameState(gameState);
|
||||
setTeamStateData(stateData);
|
||||
});
|
||||
|
||||
useOnEvent("logout", logout);
|
||||
|
||||
const value = useMemo(() => (
|
||||
{teamInfos, gameState, startDate, zoneType, zoneExtremities, nextZoneDate, messages}
|
||||
), [teamInfos, gameState, startDate, zoneType, zoneExtremities, nextZoneDate, messages]);
|
||||
{ teamId, teamName, gameState, teamStateData }
|
||||
), [teamId, teamName, gameState, teamStateData]);
|
||||
|
||||
return (
|
||||
<TeamContext.Provider value={value}>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useState, useEffect } from 'react';
|
||||
// Expo
|
||||
import * as Location from 'expo-location';
|
||||
// Constants
|
||||
import { LOCATION_PARAMETERS } from '@/constants';
|
||||
import { LOCATION_PARAMETERS } from '@/config';
|
||||
|
||||
export const useLocation = () => {
|
||||
const [location, setLocation] = useState(null);
|
||||
|
||||
@@ -2,30 +2,22 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
export const useCountdownSeconds = (date) => {
|
||||
const [time, setTime] = useState(0);
|
||||
const getSecondsTo = (newDate) => !newDate ? 0 : Math.max(0, Math.floor((newDate - Date.now()) / 1000));
|
||||
const [time, setTime] = useState(() => getSecondsTo(date));
|
||||
const [prevDate, setPrevDate] = useState(date);
|
||||
|
||||
if (date !== prevDate) {
|
||||
setPrevDate(date);
|
||||
setTime(getSecondsTo(date));
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!date) {
|
||||
setTime(0);
|
||||
return;
|
||||
}
|
||||
const interval = setInterval(() => {
|
||||
const seconds = getSecondsTo(date);
|
||||
setTime(seconds);
|
||||
if (seconds === 0) clearInterval(interval);
|
||||
}, 1000);
|
||||
|
||||
let interval;
|
||||
|
||||
const updateTime = () => {
|
||||
const timeLeft = Math.floor((date - Date.now()) / 1000);
|
||||
|
||||
if (timeLeft <= 0) {
|
||||
setTime(0);
|
||||
clearInterval(interval);
|
||||
} else {
|
||||
setTime(timeLeft);
|
||||
}
|
||||
};
|
||||
|
||||
updateTime();
|
||||
interval = setInterval(updateTime, 1000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [date]);
|
||||
|
||||
@@ -33,27 +25,18 @@ export const useCountdownSeconds = (date) => {
|
||||
};
|
||||
|
||||
export const useTimeSinceSeconds = (date) => {
|
||||
const [time, setTime] = useState(0);
|
||||
const getSecondsTo = (newDate) => !newDate ? 0 : Math.max(0, Math.floor((Date.now() - newDate) / 1000));
|
||||
const [time, setTime] = useState(() => getSecondsTo(date));
|
||||
const [prevDate, setPrevDate] = useState(date);
|
||||
|
||||
if (date !== prevDate) {
|
||||
setPrevDate(date);
|
||||
setTime(getSecondsTo(date));
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!date) {
|
||||
setTime(0);
|
||||
return;
|
||||
}
|
||||
const interval = setInterval(() => setTime(getSecondsTo(date)), 1000);
|
||||
|
||||
const updateTime = () => {
|
||||
const timeSince = Math.floor((Date.now() - date) / 1000);
|
||||
|
||||
if (timeSince <= 0) {
|
||||
setTime(0);
|
||||
} else {
|
||||
setTime(timeSince);
|
||||
}
|
||||
};
|
||||
|
||||
updateTime();
|
||||
const interval = setInterval(updateTime, 1000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [date]);
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ import { useState, useEffect, useMemo } from "react";
|
||||
import { useAuth } from "@/contexts/authContext";
|
||||
import { useTeam } from "@/contexts/teamContext";
|
||||
// Constants
|
||||
import { GAME_STATE, USER_STATE } from '@/constants';
|
||||
import { GAME_STATE, USER_STATE } from '@/config';
|
||||
import { getLocationAuthorization } from '@/services/tasks/backgroundLocation';
|
||||
|
||||
export const useUserState = () => {
|
||||
const { loggedIn } = useAuth();
|
||||
const { teamInfos, gameState } = useTeam();
|
||||
const { captured } = teamInfos;
|
||||
const { isLoggedIn } = useAuth();
|
||||
const { teamStateData, gameState } = useTeam();
|
||||
const { isEliminated } = teamStateData;
|
||||
const [isLocationAuthorized, setIsLocationAuthorized] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -25,7 +25,7 @@ export const useUserState = () => {
|
||||
return useMemo(() => {
|
||||
if (isLocationAuthorized == null) return USER_STATE.LOADING;
|
||||
if (!isLocationAuthorized) return USER_STATE.NO_LOCATION;
|
||||
if (!loggedIn) return USER_STATE.OFFLINE;
|
||||
if (!isLoggedIn) return USER_STATE.OFFLINE;
|
||||
|
||||
switch (gameState) {
|
||||
case GAME_STATE.SETUP:
|
||||
@@ -33,11 +33,11 @@ export const useUserState = () => {
|
||||
case GAME_STATE.PLACEMENT:
|
||||
return USER_STATE.PLACEMENT;
|
||||
case GAME_STATE.PLAYING:
|
||||
return captured ? USER_STATE.CAPTURED : USER_STATE.PLAYING;
|
||||
return isEliminated ? USER_STATE.CAPTURED : USER_STATE.PLAYING;
|
||||
case GAME_STATE.FINISHED:
|
||||
return captured ? USER_STATE.CAPTURED : USER_STATE.FINISHED;
|
||||
return isEliminated ? USER_STATE.CAPTURED : USER_STATE.FINISHED;
|
||||
default:
|
||||
return USER_STATE.WAITING;
|
||||
}
|
||||
}, [loggedIn, gameState, captured, isLocationAuthorized]);
|
||||
}, [isLoggedIn, gameState, isEliminated, isLocationAuthorized]);
|
||||
};
|
||||
|
||||
@@ -1,26 +1,21 @@
|
||||
import i18n from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
|
||||
// Importation des fichiers de traduction
|
||||
import fr from './locales/fr.json';
|
||||
import en from './locales/en.json';
|
||||
|
||||
// eslint-disable-next-line import/no-named-as-default-member
|
||||
i18n
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
resources: {
|
||||
en: { translation: en },
|
||||
fr: { translation: fr }
|
||||
},
|
||||
lng: 'fr',
|
||||
fallbackLng: 'en',
|
||||
interpolation: {
|
||||
escapeValue: false
|
||||
},
|
||||
react: {
|
||||
useSuspense: false
|
||||
}
|
||||
});
|
||||
i18n.use(initReactI18next).init({
|
||||
resources: {
|
||||
en: { translation: en },
|
||||
fr: { translation: fr }
|
||||
},
|
||||
lng: 'fr',
|
||||
fallbackLng: 'en',
|
||||
interpolation: {
|
||||
escapeValue: false
|
||||
},
|
||||
react: {
|
||||
useSuspense: false
|
||||
}
|
||||
});
|
||||
|
||||
export default i18n;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Constants
|
||||
import { SERVER_URL } from "@/constants";
|
||||
import { SERVER_URL } from "@/config";
|
||||
|
||||
export const uploadTeamImage = async (id, imageUri) => {
|
||||
if (!imageUri || !id) return;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Socket
|
||||
import { io } from "socket.io-client";
|
||||
// Constants
|
||||
import { SOCKET_URL } from "@/constants";
|
||||
import { SOCKET_URL } from "@/config";
|
||||
|
||||
export const socket = io(SOCKET_URL, {
|
||||
path: "/back/socket.io"
|
||||
|
||||
@@ -35,22 +35,14 @@ export const emitLogout = () => {
|
||||
return customEmit("logout");
|
||||
};
|
||||
|
||||
export const emitSendPosition = () => {
|
||||
return customEmit("send_position");
|
||||
export const emitLocation = (location) => {
|
||||
return customEmit("scan", location);
|
||||
};
|
||||
|
||||
export const emitUpdatePosition = (location) => {
|
||||
return customEmit("update_position", location);
|
||||
export const emitScan = (location) => {
|
||||
return customEmit("location", location);
|
||||
};
|
||||
|
||||
export const emitCapture = (captureCode) => {
|
||||
return customEmitCallback("capture", captureCode);
|
||||
};
|
||||
|
||||
export const emitBattery = (level) => {
|
||||
return customEmit("battery_update", level);
|
||||
};
|
||||
|
||||
export const emitDeviceInfo = (infos) => {
|
||||
return customEmit("device_info", infos);
|
||||
};
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
import { defineTask, isTaskRegisteredAsync } from "expo-task-manager";
|
||||
import * as Location from 'expo-location';
|
||||
// Services
|
||||
import { emitUpdatePosition } from "@/services/socket/emitters";
|
||||
import { emitScan } from "@/services/socket/emitters";
|
||||
// Constants
|
||||
import { TASKS, LOCATION_PARAMETERS } from "@/constants";
|
||||
import { TASKS, LOCATION_PARAMETERS } from "@/config";
|
||||
|
||||
|
||||
// Task
|
||||
@@ -22,7 +22,7 @@ defineTask(TASKS.BACKGROUND_LOCATION, async ({ data, error }) => {
|
||||
return;
|
||||
}
|
||||
const { latitude, longitude } = locations[0].coords;
|
||||
emitUpdatePosition([latitude, longitude]);
|
||||
emitScan([latitude, longitude]);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user