mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-04-11 00:30:19 +02:00
eslint for mobile + new maps API key + cleaning
This commit is contained in:
@@ -2,13 +2,13 @@ import { useSocket } from "../context/socketContext";
|
||||
import { useTeamConnexion } from "../context/teamConnexionContext";
|
||||
import { useTeamContext } from "../context/teamContext";
|
||||
|
||||
export default function useGame() {
|
||||
export const useGame = () => {
|
||||
const { teamSocket } = useSocket();
|
||||
const { teamId } = useTeamConnexion();
|
||||
const { teamInfos } = useTeamContext();
|
||||
|
||||
function sendCurrentPosition() {
|
||||
console.log("Reveal position.")
|
||||
console.log("Reveal position.");
|
||||
teamSocket.emit("send_position");
|
||||
}
|
||||
|
||||
@@ -30,4 +30,4 @@ export default function useGame() {
|
||||
}
|
||||
|
||||
return {...teamInfos, sendCurrentPosition, capture, teamId};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useLocalStorage(key, initialValue) {
|
||||
export const useLocalStorage = (key, initialValue) => {
|
||||
const [storedValue, setStoredValue] = useState(initialValue);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
@@ -16,7 +16,7 @@ export function useLocalStorage(key, initialValue) {
|
||||
setLoading(false);
|
||||
}
|
||||
fetchData();
|
||||
}, []);
|
||||
}, [initialValue, key]);
|
||||
|
||||
const setValue = async value => {
|
||||
try {
|
||||
@@ -28,7 +28,7 @@ export function useLocalStorage(key, initialValue) {
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return [storedValue, setValue, loading];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import { defineTask, isTaskRegisteredAsync } from "expo-task-manager";
|
||||
import * as Location from 'expo-location';
|
||||
import { useSocket } from "../context/socketContext";
|
||||
|
||||
export function useLocation(timeInterval, distanceInterval) {
|
||||
export const useLocation = (timeInterval, distanceInterval) => {
|
||||
const [location, setLocation] = useState(null); // [latitude, longitude]
|
||||
const { teamSocket } = useSocket();
|
||||
const LOCATION_TASK_NAME = "background-location-task";
|
||||
@@ -40,7 +40,7 @@ export function useLocation(timeInterval, distanceInterval) {
|
||||
console.log("Sending position :", new_location);
|
||||
teamSocket.emit("update_position", new_location);
|
||||
} else {
|
||||
console.log("No location measured.")
|
||||
console.log("No location measured.");
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -64,7 +64,7 @@ export function useLocation(timeInterval, distanceInterval) {
|
||||
if (await getLocationAuthorization()) {
|
||||
if (!(await isTaskRegisteredAsync(LOCATION_TASK_NAME))) {
|
||||
await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, locationUpdateParameters);
|
||||
console.log("Location tracking started.")
|
||||
console.log("Location tracking started.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,9 +72,9 @@ export function useLocation(timeInterval, distanceInterval) {
|
||||
async function stopLocationTracking() {
|
||||
if (await isTaskRegisteredAsync(LOCATION_TASK_NAME)) {
|
||||
await Location.stopLocationUpdatesAsync(LOCATION_TASK_NAME);
|
||||
console.log("Location tracking stopped.")
|
||||
console.log("Location tracking stopped.");
|
||||
}
|
||||
}
|
||||
|
||||
return [location, getLocationAuthorization, startLocationTracking, stopLocationTracking];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useState, } from 'react';
|
||||
import { Alert } from 'react-native';
|
||||
import { launchImageLibraryAsync, requestMediaLibraryPermissionsAsync } from 'expo-image-picker';
|
||||
|
||||
export function usePickImage() {
|
||||
export const usePickImage = () => {
|
||||
const [image, setImage] = useState(null);
|
||||
|
||||
const pickImage = async () => {
|
||||
@@ -33,7 +33,7 @@ export function usePickImage() {
|
||||
console.error('Error picking image;', error);
|
||||
Alert.alert('Erreur', "Une erreur est survenue lors de la sélection d'une image.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function sendImage(location) {
|
||||
if (image) {
|
||||
@@ -55,4 +55,4 @@ export function usePickImage() {
|
||||
}
|
||||
|
||||
return {image, pickImage, sendImage};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import DeviceInfo from 'react-native-device-info';
|
||||
import { useSocket } from "../context/socketContext";
|
||||
import { useTeamConnexion } from "../context/teamConnexionContext";
|
||||
|
||||
export default function useSendDeviceInfo() {
|
||||
export const useSendDeviceInfo = () => {
|
||||
const batteryUpdateTimeout = 5*60*1000;
|
||||
const { teamSocket } = useSocket();
|
||||
const {loggedIn} = useTeamConnexion();
|
||||
@@ -28,8 +28,8 @@ export default function useSendDeviceInfo() {
|
||||
|
||||
const batteryCheckInterval = setInterval(() => sendBattery(), batteryUpdateTimeout);
|
||||
|
||||
return () => {clearInterval(batteryCheckInterval)};
|
||||
}, [loggedIn]);
|
||||
return () => clearInterval(batteryCheckInterval);
|
||||
}, [batteryUpdateTimeout, loggedIn, teamSocket]);
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useLocalStorage } from './useLocalStorage';
|
||||
const LOGIN_MESSAGE = "login";
|
||||
const LOGOUT_MESSAGE = "logout";
|
||||
|
||||
export function useSocketAuth(socket, passwordName) {
|
||||
export const useSocketAuth = (socket, passwordName) => {
|
||||
const [loggedIn, setLoggedIn] = useState(false);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [waitingForResponse, setWaitingForResponse] = useState(false);
|
||||
@@ -29,7 +29,7 @@ export function useSocketAuth(socket, passwordName) {
|
||||
});
|
||||
setHasTriedSavedPassword(true);
|
||||
}
|
||||
}, [loading]);
|
||||
}, [hasTriedSavedPassword, loading, savedPassword, socket]);
|
||||
|
||||
function login(password) {
|
||||
console.log("Try to log in with :", password);
|
||||
@@ -69,4 +69,4 @@ export function useSocketAuth(socket, passwordName) {
|
||||
}, [waitingForResponse, savedPasswordLoading]);
|
||||
|
||||
return {login, logout, password: savedPassword, loggedIn, loading};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useEffect } from "react";
|
||||
|
||||
export function useSocketListener(socket, event, callback) {
|
||||
export const useSocketListener = (socket, event, callback) => {
|
||||
useEffect(() => {
|
||||
socket.on(event,callback);
|
||||
return () => {
|
||||
socket.off(event, callback);
|
||||
}
|
||||
}, []);
|
||||
}
|
||||
};
|
||||
}, [callback, event, socket]);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useTimeDifference(refTime, timeout) {
|
||||
export const useTimeDifference = (refTime, timeout) => {
|
||||
// If refTime is in the past, time will be positive
|
||||
// If refTime is in the future, time will be negative
|
||||
// The time is updated every timeout milliseconds
|
||||
@@ -15,7 +15,7 @@ export function useTimeDifference(refTime, timeout) {
|
||||
const interval = setInterval(updateTime, timeout);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [refTime]);
|
||||
}, [refTime, timeout]);
|
||||
|
||||
return [time];
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user