session updates. mostly

This commit is contained in:
2025-08-14 15:38:48 +02:00
parent e0a03f00bf
commit 368628c070
4 changed files with 83 additions and 57 deletions
+19 -5
View File
@@ -32,17 +32,30 @@ export default function Lobby() {
}
useEffect(() => {
if (sessionId) {
const socket = new WebSocket(
console.log("session: ", sessionId);
let socket;
if (sessionId && !sessionSocket) {
socket = new WebSocket(
`${process.env.NEXT_PUBLIC_WS_HOST}/voting/session/${sessionId}/`,
);
socket.onmessage = onMessage;
setSessionSocket(socket);
if (!sessionSocket) {
setSessionSocket(socket);
console.log("session made: ", sessionId);
} else {
socket.close();
}
}
return () => {
if (socket) {
socket.close();
}
};
}, [sessionId]);
function addUser(userName: string) {
if (userList.find((user) => user.name === userName)) {
console.log(userList);
if (userList.find((user) => user.name == userName)) {
return;
}
const newUser = {
@@ -51,7 +64,8 @@ export default function Lobby() {
avatar: `https://i.pravatar.cc/150?img=${userList.length + 1}`,
host: userList.length === 0,
};
setUserList((prevUserList) => [...prevUserList, newUser]);
const newUserList = [...userList, newUser];
setUserList(newUserList);
}
return (