From 7d54f6c5ce448bb57ef965c47245483a216a7418 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Sun, 17 Aug 2025 10:05:51 +0200 Subject: [PATCH] fixes userlist --- frontend/src/app/lobby/page.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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() {