diff --git a/apps/web/app/queue/page.tsx b/apps/web/app/queue/page.tsx index e9cdb55..17a3441 100644 --- a/apps/web/app/queue/page.tsx +++ b/apps/web/app/queue/page.tsx @@ -44,11 +44,19 @@ export default function Page(): JSX.Element { }, onMessage: (event) => { const data = JSON.parse(event.data); + console.log({ data }); switch (data.type) { + case "me": + setMe(data.id); + break; case "usersOnline": setUsersOnline(data.size); break; + case "roomFound": + console.log({ data }); + router.push(`/room/${data.roomId}`); + break; default: break; } @@ -56,40 +64,10 @@ export default function Page(): JSX.Element { }, ); - // useEffect(() => { - // let me = null; - // - // - // if (!socket) { - // socket = Socket(); - // } - // - // socket.on("me", (_me) => { - // me = _me; - // setMe(me); - // }); - // - // socket.on("newUserConnect", ({ size }) => { - // setUsersOnline(size); - // }); - // - // socket.on("roomFound", ({ room, roomId }) => { - // console.log({ room, roomId }); - // router.push(`/room/${roomId}?host=${room.host}`); - // }); - // - // return () => { - // socket.off("queueUpdated"); - // socket.off("newUserConnect"); - // socket.off("roomFound"); - // socket.close(); - // }; - // }, []); - const onConnect = useCallback(() => { - setInQueue(!inQueue); + setInQueue(!inQueue); // TODOO: Replace to update the state when receive it from backend sendJsonMessage({ type: inQueue ? "queueExit" : "queueJoin", userId: me }); - }, [inQueue, me]); + }, [inQueue, me, sendJsonMessage]); return (
@@ -99,6 +77,7 @@ export default function Page(): JSX.Element {

Estamos procurando alguém para praticar inglês contigo

QueueSize: {usersOnline}

acessGranted: {accessGranted}

+

userId: {me}