Skip to content

A platform for community discussion. Free, open, simple.

DEV: dry up the Do Not Disturb widget (#19494)

Andrei Prigorshnevb334f0070dc5
diff --git a/app/assets/javascripts/discourse/app/widgets/do-not-disturb.js b/app/assets/javascripts/discourse/app/widgets/do-not-disturb.js
index d5989c6290a..4afa4f2127f 100644
--- a/app/assets/javascripts/discourse/app/widgets/do-not-disturb.js
+++ b/app/assets/javascripts/discourse/app/widgets/do-not-disturb.js
@@ -11,21 +11,8 @@ export default createWidget("do-not-disturb", {
saving: false,
html() {
- if (this.currentUser.isInDoNotDisturb()) {
- return [
- h("button.btn-flat.do-not-disturb-inner-container", [
- iconNode("toggle-on"),
- this.label(),
- ]),
- ];
- } else {
- return [
- h("button.btn-flat.do-not-disturb-inner-container", [
- iconNode("toggle-off"),
- h("span.do-not-disturb-label", I18n.t("pause_notifications.label")),
- ]),
- ];
- }
+ const isOn = this.currentUser.isInDoNotDisturb();
+ return [this._menuButton(isOn)];
},
click() {
@@ -44,7 +31,15 @@ export default createWidget("do-not-disturb", {
}
},
- label() {
+ _menuButton(isOn) {
+ const icon = iconNode(isOn ? "toggle-on" : "toggle-off");
+ return h("button.btn-flat.do-not-disturb-inner-container", [
+ icon,
+ this._label(),
+ ]);
+ },
+
+ _label() {
const content = [h("span", I18n.t("pause_notifications.label"))];
const until = this.currentUser.do_not_disturb_until;