Fixed votes counted not being counted.

This commit is contained in:
armored-dragon 2024-09-12 02:57:17 -05:00
parent 3067deab63
commit e00e78aa24
No known key found for this signature in database
GPG key ID: C7207ACC3382AD8B
2 changed files with 37 additions and 53 deletions

View file

@ -18,6 +18,7 @@
// TODO: Voting results page
// TODO: Joining poll sometimes causes to double stack on other clients poll_list?
// TODO: Do active polls persist across domain leave? If so close them on session leave
// FIXME: Empty arrays in responses don't count as valid votes anymore? Causes miscounts?
(() => {
"use strict";
@ -280,6 +281,10 @@
function _debugDummyBallot() {
if (!debug) return; // Just incase...
let ballot = getRandomOrder(...poll.options);
const indexToRemove = Math.floor(Math.random() * ballot.length);
ballot.splice(indexToRemove, 1);
const responsesKeyName = Object.keys(responses).length.toString();
responses[responsesKeyName] = ballot;
@ -288,6 +293,7 @@
const j = Math.floor(Math.random() * (i + 1));
[words[i], words[j]] = [words[j], words[i]];
}
return words;
}
}
@ -398,6 +404,10 @@
poll.question = message.prompt.question;
}
if (message.type == "vote_count") {
_emitEvent({type: "received_vote", voteCount: message.voteCount});
}
// Received a ballot
if (message.type == "vote") {
// Check if we are the host
@ -409,12 +419,13 @@
// Emit a echo so the voter knows we have received it
// TODO:
// console.log(JSON.stringify(responses));
// Broadcast the updated count to all clients
Messages.sendMessage(poll.id, JSON.stringify({type: "vote_count", voteCount: Object.keys(responses).length}));
}
// Winner was broadcasted
if (message.type == "poll_winner") {
_emitEvent({type: "poll_winner", winner: message.winner, rounds: message.rounds, votesCounted: message.votes});
_emitEvent({type: "poll_winner", winner: message.winner, rounds: message.rounds, votesCounted: message.votesCounted});
}
}

View file

@ -544,12 +544,30 @@ Rectangle {
font.pointSize: 12
}
Text {
id: tally_votes_received
text: "0"
color: "white"
font.pointSize: 14
}
}
RowLayout {
width: parent.width
Text {
text: "Votes counted:"
color: "gray"
Layout.fillWidth: true
font.pointSize: 12
}
Text {
id: tally_votes_counted
text: "-"
color: "white"
font.pointSize: 14
}
}
RowLayout {
width: parent.width
@ -560,6 +578,7 @@ Rectangle {
font.pointSize: 12
}
Text {
id: tally_votes_itterations
text: "-"
color: "white"
font.pointSize: 14
@ -645,57 +664,6 @@ Rectangle {
}
}
}
// TODO: View a list of the ballots and the results of the election rounds
// Item {
// Layout.fillHeight: true
// Layout.fillWidth: true
// // TODO: Allow scrolling
// ScrollView {
// // ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
// // ScrollBar.vertical.policy: ScrollBar.AlwaysOff
// clip: true
// width: parent.width
// height: parent.height
// ColumnLayout {
// Repeater {
// model: 3
// ColumnLayout {
// Text {
// text: "Round "+ index +": Eleminated XXX"
// font.pointSize: 18
// color: "white"
// }
// Repeater {
// model: 20
// RowLayout {
// height: 30
// Repeater {
// model: 4
// Item {
// width: 100
// height: 30
// Text {
// text: 'One ' + index
// color: "white"
// font.pointSize: 12
// width: parent.width - 10
// }
// }
// }
// }
// }
// }
// }
// }
// }
// }
}
@ -966,6 +934,11 @@ Rectangle {
break;
case "poll_winner":
poll_winner.text = message.winner
tally_votes_itterations.text = message.rounds
tally_votes_counted.text = message.votesCounted
break;
case "received_vote":
tally_votes_received.text = message.voteCount
break;
}
}