Fix vote bug
This commit is contained in:
@@ -76,14 +76,34 @@ export const WaitingRoom = () => {
|
||||
};
|
||||
|
||||
const handlePlaylistOptions = (options) => {
|
||||
setPlaylists(options);
|
||||
const playlistsWithVotes = { ...options };
|
||||
Object.keys(playlistsWithVotes).forEach(genre => {
|
||||
const playlistId = playlistsWithVotes[genre].id;
|
||||
playlistsWithVotes[genre].votes = votes[playlistId]?.length || 0;
|
||||
});
|
||||
setPlaylists(playlistsWithVotes);
|
||||
};
|
||||
|
||||
const handleVotesUpdated = (newVotes) => {
|
||||
console.log('Received updated votes:', newVotes);
|
||||
setVotes(newVotes);
|
||||
|
||||
setPlaylists(current => {
|
||||
const updated = { ...current };
|
||||
Object.keys(updated).forEach(genre => {
|
||||
const playlistId = updated[genre].id;
|
||||
updated[genre].votes = newVotes[playlistId]?.length || 0;
|
||||
});
|
||||
return updated;
|
||||
});
|
||||
|
||||
Object.entries(newVotes).forEach(([playlistId, voters]) => {
|
||||
if (voters.includes(socket.id)) {
|
||||
setSelectedPlaylist(playlistId);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Register event listeners
|
||||
const cleanupHostStatus = on("host-status", handleHostStatus);
|
||||
const cleanupUserInfo = on("user-info", handleUserInfo);
|
||||
const cleanupRoomUsers = on("room-users", handleRoomUsers);
|
||||
|
Reference in New Issue
Block a user