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
This commit is contained in:
David Taylor 2019-07-31 15:31:02 +01:00
parent 13e74151a9
commit a49b7bb84a
1 changed files with 21 additions and 42 deletions

View File

@ -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) {