diff --git a/assets/javascripts/discourse/components/teambuild-choice.gjs b/assets/javascripts/discourse/components/teambuild-choice.gjs index f2039b2..1235484 100644 --- a/assets/javascripts/discourse/components/teambuild-choice.gjs +++ b/assets/javascripts/discourse/components/teambuild-choice.gjs @@ -1,12 +1,11 @@ import Component from "@ember/component"; -import { action, computed } from "@ember/object"; +import { action } from "@ember/object"; import { tagName } from "@ember-decorators/component"; import DButton from "discourse/components/d-button"; import icon from "discourse/helpers/d-icon"; @tagName("") export default class TeambuildChoice extends Component { - @computed("progress.completed.[]") get completed() { return this.progress.isComplete(this.target, this.userId); } diff --git a/assets/javascripts/discourse/models/teambuild-progress.js b/assets/javascripts/discourse/models/teambuild-progress.js index 264d439..b98e255 100644 --- a/assets/javascripts/discourse/models/teambuild-progress.js +++ b/assets/javascripts/discourse/models/teambuild-progress.js @@ -1,4 +1,9 @@ import { popupAjaxError } from "discourse/lib/ajax-error"; +import { + addUniqueValueToArray, + removeValueFromArray, +} from "discourse/lib/array-tools"; +import { trackedArray } from "discourse/lib/tracked-tools"; import RestModel from "discourse/models/rest"; function choiceKey(target, userId) { @@ -6,6 +11,8 @@ function choiceKey(target, userId) { } export default class TeambuildProgress extends RestModel { + @trackedArray completed = []; + isComplete(target, userId) { return this.completed.includes(choiceKey(target, userId)); } @@ -14,7 +21,7 @@ export default class TeambuildProgress extends RestModel { target .complete(userId) .then(() => { - this.completed.addObject(choiceKey(target, userId)); + addUniqueValueToArray(this.completed, choiceKey(target, userId)); }) .catch(popupAjaxError); } @@ -23,7 +30,7 @@ export default class TeambuildProgress extends RestModel { target .undo(userId) .then(() => { - this.completed.removeObject(choiceKey(target, userId)); + removeValueFromArray(this.completed, choiceKey(target, userId)); }) .catch(popupAjaxError); }