From 26c4d1398a34c7a656627221834a53921a6db868 Mon Sep 17 00:00:00 2001 From: Robert <35533304+merefield@users.noreply.github.com> Date: Fri, 2 Aug 2024 07:50:33 +0100 Subject: [PATCH] FIX: update voter information upon remote change (#28168) Fixes issue with polls not being fully updated by remote vote contributions in (semi-) real-time. This was down to too great a focus on tracking local state and not accommodating a more data down approach with responsive getters. This is now implemented. I've tried hard to minimise the changes whilst making sure the paradigm is properly followed through. --- .../poll-option-ranked-choice-dropdown.gjs | 14 +- .../discourse/components/poll-options.gjs | 2 +- .../components/poll-results-standard.gjs | 7 +- .../javascripts/discourse/components/poll.gjs | 370 ++++++++++-------- .../discourse/widgets/discourse-poll.js | 3 +- .../test/javascripts/component/poll-test.js | 62 ++- 6 files changed, 264 insertions(+), 194 deletions(-) diff --git a/plugins/poll/assets/javascripts/discourse/components/poll-option-ranked-choice-dropdown.gjs b/plugins/poll/assets/javascripts/discourse/components/poll-option-ranked-choice-dropdown.gjs index f3a0b4f777e..aa48b8d7fcb 100644 --- a/plugins/poll/assets/javascripts/discourse/components/poll-option-ranked-choice-dropdown.gjs +++ b/plugins/poll/assets/javascripts/discourse/components/poll-option-ranked-choice-dropdown.gjs @@ -1,5 +1,4 @@ import Component from "@glimmer/component"; -import { tracked } from "@glimmer/tracking"; import { fn } from "@ember/helper"; import { action } from "@ember/object"; import DButton from "discourse/components/d-button"; @@ -9,13 +8,6 @@ import I18n from "discourse-i18n"; import DMenu from "float-kit/components/d-menu"; export default class PollOptionsDropdownComponent extends Component { - @tracked rank; - - constructor() { - super(...arguments); - this.rank = this.args.rank; - } - @action onRegisterApi(api) { this.dMenu = api; @@ -24,15 +16,13 @@ export default class PollOptionsDropdownComponent extends Component { @action selectRank(option, rank) { this.args.sendRank(option, rank); - this.rank = - rank === 0 ? I18n.t("poll.options.ranked_choice.abstain") : rank; this.dMenu.close(); } get rankLabel() { - return this.rank === 0 + return this.args.rank === 0 ? I18n.t("poll.options.ranked_choice.abstain") - : this.rank; + : this.args.rank; }