From b334f0070dc5b11e73670e1ecede5dc4a2e38400 Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Mon, 30 Jan 2023 21:23:06 +0400 Subject: [PATCH] DEV: dry up the Do Not Disturb widget (#19494) --- .../discourse/app/widgets/do-not-disturb.js | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) 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;