Implemented player login

This commit is contained in:
Quentin Roussel
2024-03-26 03:35:19 +01:00
parent b23d2a63e6
commit 7d75e91c80
16 changed files with 182 additions and 130 deletions

View File

@@ -1,11 +1,26 @@
"use client";
import { createContext, useContext, useState } from "react";
import { createContext, useContext, useEffect, useState } from "react";
import { useSocket } from "./socketContext";
import { useSocketListener } from "@/hook/useSocketListener";
import { useAdminConnexion } from "./adminConnexionContext";
const adminContext = createContext();
function AdminProvider({children}) {
const [teams, setTeams] = useState([]);
const [started, setStarted] = useState(false);
const { adminSocket } = useSocket();
const {loggedIn} = useAdminConnexion();
//Send a request to get the teams when the user logs in
useEffect(() => {
adminSocket.emit("get_teams");
}, [loggedIn]);
//Bind listeners to update the team list and the game status on socket message
useSocketListener(adminSocket, "teams", setTeams);
useSocketListener(adminSocket, "game_started", setStarted);
return (
<adminContext.Provider value={{teams, setTeams, started, setStarted}}>
{children}