Don't allow late votes.

Clear poll create screen.
This commit is contained in:
armored-dragon 2024-09-13 00:25:26 -05:00
parent 202198cbc5
commit 8a6f7dd394
No known key found for this signature in database
GPG key ID: C7207ACC3382AD8B
2 changed files with 17 additions and 2 deletions

View file

@ -12,7 +12,6 @@
/* global Script Tablet Messages MyAvatar Uuid*/
// TODO: Documentation
// FIXME: Reset create_poll view when switching screens
// FIXME: Handle ties: kill both of tied results
// FIXME: Handle ties: Last two standing are tied.
@ -29,6 +28,7 @@
let responses = {}; // All ballots received and to be used by the election function.
let electionIterations = 0; // How many times the election function has been called to narrow down a candidate.
let activePolls = []; // All active polls.
let winnerSelected = false; // Whether or not the election function has selected a winner for the active poll
const url = Script.resolvePath("./vote.qml");
const myUuid = generateUUID(MyAvatar.sessionUUID);
@ -187,6 +187,9 @@
// Check if poll is valid
if (poll == undefined || poll.id == '') return;
// Check if a winner was already chosen
if (winnerSelected) return;
// Send vote to users in poll
Messages.sendMessage(poll.id, JSON.stringify({type: "vote", ballot: event.ballot, uuid: myUuid}));
}
@ -433,6 +436,8 @@
_emitEvent({type: "poll_prompt", prompt: message.prompt});
poll.question = message.prompt.question;
winnerSelected = false;
}
if (message.type == "vote_count") {
@ -456,6 +461,7 @@
// Winner was broadcasted
if (message.type == "poll_winner") {
winnerSelected = true;
_emitEvent({type: "poll_winner", winner: message.winner, rounds: message.rounds, votesCounted: message.votesCounted});
}

View file

@ -95,7 +95,7 @@ Rectangle {
TextField {
width: 300
height: 30
text: "New Poll"
text: MyAvatar.displayName + "'s Poll"
cursorVisible: false
font.pointSize: 16
Layout.fillWidth: true
@ -124,6 +124,7 @@ Rectangle {
}
// Options
RowLayout {
width: parent.width
@ -135,6 +136,7 @@ Rectangle {
}
CheckBox {
id: poll_to_create_host_can_vote
width: 30
height: 25
checked: false
@ -182,6 +184,7 @@ Rectangle {
anchors.fill: parent
onClicked: {
toScript({type: "create_poll", poll: {title: poll_to_create_title.text, description: poll_to_create_description.text}});
_clearHostCreate();
}
}
}
@ -906,6 +909,11 @@ Rectangle {
poll_option_model_host.clear();
}
function _clearHostCreate() {
poll_to_create_title.text = MyAvatar.displayName + "'s Poll";
poll_to_create_description.text = "Vote on things!";
}
// Messages from script
function fromScript(message) {
switch (message.type){
@ -963,6 +971,7 @@ Rectangle {
// Set variables
is_host = false
poll_to_create_host_can_vote.checked = false;
break;