mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 18:20:17 +01:00
Implemented player login
This commit is contained in:
31
traque-front/context/teamConnexionContext.jsx
Normal file
31
traque-front/context/teamConnexionContext.jsx
Normal file
@@ -0,0 +1,31 @@
|
||||
"use client";
|
||||
import { createContext, useContext, useState } from "react";
|
||||
import { useSocket } from "./socketContext";
|
||||
import { useSocketListener } from "@/hook/useSocketListener";
|
||||
|
||||
const teamConnexionContext = createContext();
|
||||
const TeamConnexionProvider = ({ children }) => {
|
||||
const [loggedIn, setLoggedIn] = useState(false);
|
||||
const [teamId, setTeamId] = useState(null);
|
||||
const { teamSocket } = useSocket();
|
||||
|
||||
function login(id) {
|
||||
teamSocket.emit("login", id);
|
||||
setTeamId(id);
|
||||
}
|
||||
|
||||
useSocketListener(teamSocket, "login_response", setLoggedIn);
|
||||
|
||||
return (
|
||||
<teamConnexionContext.Provider value={{ teamId, login, loggedIn }}>
|
||||
{children}
|
||||
</teamConnexionContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
function useTeamConnexion() {
|
||||
return useContext(teamConnexionContext);
|
||||
}
|
||||
|
||||
export { TeamConnexionProvider, useTeamConnexion};
|
||||
|
||||
Reference in New Issue
Block a user