Skip to content

Commit

Permalink
total score data updated
Browse files Browse the repository at this point in the history
  • Loading branch information
BhanuArora123 committed Oct 30, 2022
1 parent 36fefe7 commit 76ea845
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions Frontend/src/pages/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,28 @@ const Room = ({users, setUsers}) => {
profile:{
...user
},
score:0,
_id:user.userId,
userName:user.handle
}
},
score:0,
}];
console.log("curr",curr);
return curr;
})
});

socket.on("total_score", (data) => {
console.log("here3");
console.log("data: ", data);
let userId = data.userId;
let userIndex = users.findIndex(user => user.userId._id.toString() === userId.toString());
if(userIndex === -1){
return ;
}
users[userIndex].score = data.totalScore;
setUsers(users);
})

// browser back button handling i.e leaving the room
window.onpopstate = () => {
axios.post("http://localhost:4000/rooms/leaveRoom", {
Expand Down Expand Up @@ -110,17 +122,6 @@ const Room = ({users, setUsers}) => {
})
},500000)
console.log("run",socket);
socket.on("total_score", (data) => {
console.log("here3");
console.log("data: ", data);
let userId = data.userId;
let userIndex = users.findIndex(user => user.userId._id.toString() === userId.toString());
if(userIndex === -1){
return ;
}
users[userIndex].score = data.totalScore;
setUsers(users);
})

}, []);

Expand Down

0 comments on commit 76ea845

Please sign in to comment.