FIX: Prevent user-notifications-dropdown from causing unintended changes

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

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 f9060e9..2289b2f 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) {

GitHub sha: a49b7bb8

1 Like