mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 09:43:46 +08:00
0431942f3d
This new iteration of select-kit focuses on following best principales and disallowing mutations inside select-kit components. A best effort has been made to avoid breaking changes, however if you content was a flat array, eg: ["foo", "bar"] You will need to set valueProperty=null and nameProperty=null on the component. Also almost every component should have an `onChange` handler now to decide what to do with the updated data. **select-kit will not mutate your data by itself anymore**
71 lines
1.8 KiB
JavaScript
71 lines
1.8 KiB
JavaScript
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/object";
|
|
|
|
export default DropdownSelectBox.extend({
|
|
classNames: ["user-notifications", "user-notifications-dropdown"],
|
|
|
|
selectKitOptions: {
|
|
headerIcon: "userNotificationicon"
|
|
},
|
|
|
|
userNotificationicon: computed("mainCollection.[]", "value", function() {
|
|
return (
|
|
this.mainCollection &&
|
|
this.mainCollection.find(row => row.id === this.value).icon
|
|
);
|
|
}),
|
|
|
|
content: computed(function() {
|
|
const content = [];
|
|
|
|
content.push({
|
|
icon: "user",
|
|
id: "changeToNormal",
|
|
description: I18n.t("user.user_notifications.normal_option_title"),
|
|
name: I18n.t("user.user_notifications.normal_option")
|
|
});
|
|
|
|
content.push({
|
|
icon: "times-circle",
|
|
id: "changeToMuted",
|
|
description: I18n.t("user.user_notifications.mute_option_title"),
|
|
name: I18n.t("user.user_notifications.mute_option")
|
|
});
|
|
|
|
if (this.get("user.can_ignore_user")) {
|
|
content.push({
|
|
icon: "far-eye-slash",
|
|
id: "changeToIgnored",
|
|
description: I18n.t("user.user_notifications.ignore_option_title"),
|
|
name: I18n.t("user.user_notifications.ignore_option")
|
|
});
|
|
}
|
|
|
|
return content;
|
|
}),
|
|
|
|
changeToNormal() {
|
|
this.updateNotificationLevel("normal").catch(popupAjaxError);
|
|
},
|
|
changeToMuted() {
|
|
this.updateNotificationLevel("mute").catch(popupAjaxError);
|
|
},
|
|
changeToIgnored() {
|
|
showModal("ignore-duration", {
|
|
model: this.user
|
|
});
|
|
},
|
|
|
|
actions: {
|
|
onChange(level) {
|
|
this[level]();
|
|
|
|
// hack but model.ignored/muted is not
|
|
// getting updated after updateNotificationLevel
|
|
this.set("value", level);
|
|
}
|
|
}
|
|
});
|