From 4eea4a09f07273ac1edc170bd98b247fe4ec6291 Mon Sep 17 00:00:00 2001 From: armored-dragon Date: Wed, 4 Sep 2024 14:44:39 -0500 Subject: [PATCH] Poll closure syncing. --- applications/voting/vote.js | 18 ++++++------------ applications/voting/vote.qml | 14 +++++++++----- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/applications/voting/vote.js b/applications/voting/vote.js index 4d4c60b..14ce958 100644 --- a/applications/voting/vote.js +++ b/applications/voting/vote.js @@ -12,13 +12,7 @@ /* global Script Tablet Messages MyAvatar Uuid*/ // TODO: Documentation -// TODO: Start poll -// TODO: View active polls -// TODO: Join poll -// TODO: Create poll question and answers -// TODO: Create pre-fill answers (checkbox?) // TODO: Save questions and answers locally -// TODO: View previous answers (() => { "use strict"; @@ -115,17 +109,17 @@ function deletePoll(){ // Check to see if we are hosting the poll if (poll.host != myUuid) return; // We are not the host of this poll - + console.log("Closing active poll"); // Submit the termination message to all clients - Messages.sendMessage("ga-polls", JSON.stringify({type: "close_poll"})); + Messages.sendMessage("ga-polls", JSON.stringify({type: "close_poll", poll: {id: poll.id}})); + + // Update the UI screen + _emitEvent({type: "close_poll", poll: {id: poll.id}}); // Clear our active poll data poll = { host: '', title: '', description: '', id: '', question: '', options: []}; - - // Update the UI screen - _emitEvent({type: "close_poll"}); } // Join an existing poll hosted by another user @@ -250,8 +244,8 @@ // Polls closed :) if (message.type == "close_poll") { + _emitEvent({type: "close_poll", poll: {id: message.poll.id}}); leavePoll(); - _emitEvent({type: "close_poll"}); } break; diff --git a/applications/voting/vote.qml b/applications/voting/vote.qml index a11e49a..07b7015 100644 --- a/applications/voting/vote.qml +++ b/applications/voting/vote.qml @@ -84,7 +84,6 @@ Rectangle { Layout.fillWidth: true font.pointSize: 18 color: "white" - // Layout.fillHeight: true } TextField { width: 300 @@ -621,8 +620,6 @@ Rectangle { // Add poll info to the list of active polls case "new_poll": - console.log("\n\nWe are doing the thing") - console.log(JSON.stringify(message.poll)) active_polls.append(message.poll) break; @@ -642,8 +639,15 @@ Rectangle { break; case "close_poll": current_page = "poll_list" - // TODO: Delete poll off of the list - // TODO: Clear poll client view? + + // Find the poll with the matching ID and remove it from active polls + for (var i = 0; i < active_polls.count; i++) { + var element = active_polls.get(i); + if (element.id == message.poll.id) { + active_polls.remove(i); + } + } + break; } }