From a49b7bb84ad90535ae1ae8f9b4fa967b180c7a94 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 31 Jul 2019 15:31:02 +0100 Subject: [PATCH] FIX: Prevent user-notifications-dropdown from causing unintended changes It was setting the `onClose` property of the singleton modal controller, which would then persist until the next full page reload --- .../user-notifications-dropdown.js.es6 | 63 +++++++------------ 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/app/assets/javascripts/select-kit/components/user-notifications-dropdown.js.es6 b/app/assets/javascripts/select-kit/components/user-notifications-dropdown.js.es6 index f9060e99d00..2289b2f6672 100644 --- a/app/assets/javascripts/select-kit/components/user-notifications-dropdown.js.es6 +++ b/app/assets/javascripts/select-kit/components/user-notifications-dropdown.js.es6 @@ -1,23 +1,12 @@ import DropdownSelectBox from "select-kit/components/dropdown-select-box"; import { popupAjaxError } from "discourse/lib/ajax-error"; import showModal from "discourse/lib/show-modal"; +import computed from "ember-addons/ember-computed-decorators"; export default DropdownSelectBox.extend({ classNames: ["user-notifications", "user-notifications-dropdown"], nameProperty: "label", - init() { - this._super(...arguments); - if (this.get("user.ignored")) { - this.set("headerIcon", "eye-slash"); - this.set("value", "changeToIgnored"); - } else if (this.get("user.muted")) { - this.set("headerIcon", "times-circle"); - this.set("value", "changeToMuted"); - } else { - this.set("headerIcon", "user"); - this.set("value", "changeToNormal"); - } - }, + computeContent() { const content = []; @@ -47,42 +36,32 @@ export default DropdownSelectBox.extend({ return content; }, + @computed("value") + headerIcon(value) { + return this.computeContent().find(row => row.id === value).icon; + }, + changeToNormal() { - this.updateNotificationLevel("normal") - .then(() => { - this.set("user.ignored", false); - this.set("user.muted", false); - this.set("headerIcon", "user"); - }) - .catch(popupAjaxError); + this.updateNotificationLevel("normal").catch(popupAjaxError); }, changeToMuted() { - this.updateNotificationLevel("mute") - .then(() => { - this.set("user.ignored", false); - this.set("user.muted", true); - this.set("headerIcon", "times-circle"); - }) - .catch(popupAjaxError); + this.updateNotificationLevel("mute").catch(popupAjaxError); }, changeToIgnored() { - const controller = showModal("ignore-duration", { + showModal("ignore-duration", { model: this.user }); - controller.setProperties({ - onSuccess: () => { - this.set("headerIcon", "eye-slash"); - }, - onClose: () => { - if (this.get("user.muted")) { - this.set("headerIcon", "times-circle"); - this._select("changeToMuted"); - } else if (!this.get("user.muted") && !this.get("user.ignored")) { - this.set("headerIcon", "user"); - this._select("changeToNormal"); - } - } - }); + }, + + @computed("user.ignored", "user.muted") + value() { + if (this.get("user.ignored")) { + return "changeToIgnored"; + } else if (this.get("user.muted")) { + return "changeToMuted"; + } else { + return "changeToNormal"; + } }, _select(id) {