import { useRouter } from "next/router"; import { useContext, useEffect, useState } from "react"; import { useWebsocketContext, WebsocketContext, } from "../../context/websocket.context.js"; import { checkRoom, getRoom, joinRoom } from "../../requests/requests.room.js"; import styles from "../../styles/room/join.module.scss"; import { parseClassName } from "../../utils/utils.js"; import Layout from "../Layout.js"; export default function Join() { const [infos, setInfos] = useState({ nick: "", pin: "", reconnectCode: "", joined: null, }); const router = useRouter(); const { connect, send, isConnected } = useContext(WebsocketContext); useEffect(() => { if (router.query.mode.length == 2) { checkRoom(router.query.mode[1]) .then((res) => { console.log("SerInfos"); connect(`ws://192.168.1.18:8000/ws/room/${res.id_code}`); setInfos({ ...infos, pin: res.id_code, joined: false }); }) .catch((err) => { router.push({ pathname: "/room/join" }, undefined, { shallow: true }); }); } }, []); const [errorRoom, setErrorRoom] = useState({ message: "" }); return (
{infos.joined == null && ( <>

Rejoindre une salle

{ setInfos({ ...infos, pin: e.target.value }); }} />

{errorRoom.message}

)} {infos.joined == false && ( <>

Entrez un pseudo

{ setInfos({ ...infos, nick: e.target.value }); }} />

{errorRoom.message}

Ou un code de reconnexion

{ setInfos({ ...infos, reconnectCode: e.target.value }); }} />

{errorRoom.message}

)}
); }