diff --git a/frontend/src/app/lobby/page.tsx b/frontend/src/app/lobby/page.tsx index 821de6d..9649ec2 100644 --- a/frontend/src/app/lobby/page.tsx +++ b/frontend/src/app/lobby/page.tsx @@ -74,17 +74,19 @@ export default function Lobby() { } function addUser(user: object) { - console.log(userList); - // if (userList.find((u) => u.name == user?.["username"])) { - // return; - // } const newUser = { id: user["id"], name: user["username"], avatar: `https://i.pravatar.cc/150?img=${user["id"]}`, }; - setUserList([...userList, newUser]); + setUserList((prevUserList) => { + if (prevUserList.find((u) => u.id === user["id"])) { + console.log("User already exists, not adding"); + return prevUserList; + } + return [...prevUserList, newUser]; + }); } async function getTrack() {