mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
fixed frontend for #10
This commit is contained in:
@@ -8,19 +8,21 @@ import { useTeamConnexion } from "./teamConnexionContext";
|
||||
const teamContext = createContext()
|
||||
function TeamProvider({children}) {
|
||||
const [enemyPosition, setEnemyPosition] = useState();
|
||||
const currentPosition = useLocation(10000);
|
||||
const [currentPosition, setCurrentPosition] = useState();
|
||||
const measuredLocation = useLocation(10000);
|
||||
const {teamSocket} = useSocket();
|
||||
const {loggedIn} = useTeamConnexion();
|
||||
|
||||
useSocketListener(teamSocket, "enemy_position", setEnemyPosition);
|
||||
useSocketListener(teamSocket, "live_location", setCurrentPosition);
|
||||
|
||||
//Send the current position to the server when the user is logged in
|
||||
useEffect(() => {
|
||||
console.log("sending position", currentPosition);
|
||||
console.log("sending position", measuredLocation);
|
||||
if(loggedIn) {
|
||||
teamSocket.emit("update_position", currentPosition);
|
||||
teamSocket.emit("update_position", measuredLocation);
|
||||
}
|
||||
}, [loggedIn, currentPosition]);
|
||||
}, [loggedIn, measuredLocation]);
|
||||
|
||||
const value = useMemo(() => ({enemyPosition, currentPosition}), [enemyPosition, currentPosition]);
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user