Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions assets/javascripts/discourse/components/teambuild-choice.gjs
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down
11 changes: 9 additions & 2 deletions assets/javascripts/discourse/models/teambuild-progress.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
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) {
return `${target.id}:${userId}`;
}

export default class TeambuildProgress extends RestModel {
@trackedArray completed = [];

isComplete(target, userId) {
return this.completed.includes(choiceKey(target, userId));
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down