Fix vote bug

This commit is contained in:
2025-03-01 17:17:00 +01:00
parent 9901c1a49e
commit 2ea81493ba
3 changed files with 55 additions and 13 deletions

View File

@@ -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);