From 9a6bbac5bdf2772f2b00039ac2346047c515e4c6 Mon Sep 17 00:00:00 2001 From: Ted Johansson Date: Thu, 20 Jul 2023 10:49:58 +0800 Subject: [PATCH] DEV: migrate ignore duration to Glimmer and DModal (#22687) This PR migrates the ignore modal to a Glimmer component and DModal. Most of the code is lift-and-shift. --- .../app/components/ignored-user-list.js | 18 ++--- .../modal/ignore-duration-with-username.hbs | 36 ++++++++++ .../modal/ignore-duration-with-username.js | 68 +++++++++++++++++++ .../ignore-duration-with-username.js | 65 ------------------ .../modal/ignore-duration-with-username.hbs | 32 --------- 5 files changed, 114 insertions(+), 105 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/modal/ignore-duration-with-username.hbs create mode 100644 app/assets/javascripts/discourse/app/components/modal/ignore-duration-with-username.js delete mode 100644 app/assets/javascripts/discourse/app/controllers/ignore-duration-with-username.js delete mode 100644 app/assets/javascripts/discourse/app/templates/modal/ignore-duration-with-username.hbs diff --git a/app/assets/javascripts/discourse/app/components/ignored-user-list.js b/app/assets/javascripts/discourse/app/components/ignored-user-list.js index 0ecbc713b45..487c6525464 100644 --- a/app/assets/javascripts/discourse/app/components/ignored-user-list.js +++ b/app/assets/javascripts/discourse/app/components/ignored-user-list.js @@ -1,9 +1,11 @@ import Component from "@ember/component"; +import { inject as service } from "@ember/service"; import User from "discourse/models/user"; import { popupAjaxError } from "discourse/lib/ajax-error"; -import showModal from "discourse/lib/show-modal"; +import IgnoreDurationModal from "./modal/ignore-duration-with-username"; export default Component.extend({ + modal: service(), item: null, actions: { removeIgnoredUser(item) { @@ -20,13 +22,13 @@ export default Component.extend({ }); }, newIgnoredUser() { - const modal = showModal("ignore-duration-with-username", { - model: this.model, - }); - modal.setProperties({ - ignoredUsername: null, - onUserIgnored: (username) => { - this.items.addObject(username); + this.modal.show(IgnoreDurationModal, { + model: { + actingUser: this.model, + ignoredUsername: null, + onUserIgnored: (username) => { + this.items.addObject(username); + }, }, }); }, diff --git a/app/assets/javascripts/discourse/app/components/modal/ignore-duration-with-username.hbs b/app/assets/javascripts/discourse/app/components/modal/ignore-duration-with-username.hbs new file mode 100644 index 00000000000..b5149a12a80 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/modal/ignore-duration-with-username.hbs @@ -0,0 +1,36 @@ + + <:body> +
+ + +
+ +

{{i18n "user.user_notifications.ignore_duration_note"}}

+ + <:footer> + + + +
\ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/modal/ignore-duration-with-username.js b/app/assets/javascripts/discourse/app/components/modal/ignore-duration-with-username.js new file mode 100644 index 00000000000..43e4abedd4e --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/modal/ignore-duration-with-username.js @@ -0,0 +1,68 @@ +import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; +import { action } from "@ember/object"; +import { inject as service } from "@ember/service"; +import I18n from "I18n"; +import User from "discourse/models/user"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import { timeShortcuts } from "discourse/lib/time-shortcut"; + +export default class IgnoreDurationModal extends Component { + @service currentUser; + + @tracked flash; + + @tracked loading = false; + @tracked ignoredUntil = null; + @tracked ignoredUsername = null; + + get timeShortcuts() { + const timezone = this.currentUser.user_option.timezone; + const shortcuts = timeShortcuts(timezone); + return [ + shortcuts.laterToday(), + shortcuts.tomorrow(), + shortcuts.laterThisWeek(), + shortcuts.thisWeekend(), + shortcuts.monday(), + shortcuts.twoWeeks(), + shortcuts.nextMonth(), + shortcuts.twoMonths(), + shortcuts.threeMonths(), + shortcuts.fourMonths(), + shortcuts.sixMonths(), + shortcuts.oneYear(), + shortcuts.forever(), + ]; + } + + @action + ignore() { + if (!this.ignoredUntil || !this.ignoredUsername) { + this.flash = I18n.t( + "user.user_notifications.ignore_duration_time_frame_required" + ); + return; + } + this.loading = true; + User.findByUsername(this.ignoredUsername).then((user) => { + user + .updateNotificationLevel({ + level: "ignore", + expiringAt: this.ignoredUntil, + actingUser: this.args.model.actingUser, + }) + .then(() => { + this.args.model.onUserIgnored(this.ignoredUsername); + this.args.closeModal(); + }) + .catch(popupAjaxError) + .finally(() => (this.loading = false)); + }); + } + + @action + updateIgnoredUsername(selected) { + this.ignoredUsername = selected.firstObject; + } +} diff --git a/app/assets/javascripts/discourse/app/controllers/ignore-duration-with-username.js b/app/assets/javascripts/discourse/app/controllers/ignore-duration-with-username.js deleted file mode 100644 index 89c5250382d..00000000000 --- a/app/assets/javascripts/discourse/app/controllers/ignore-duration-with-username.js +++ /dev/null @@ -1,65 +0,0 @@ -import Controller from "@ember/controller"; -import I18n from "I18n"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; -import User from "discourse/models/user"; -import { popupAjaxError } from "discourse/lib/ajax-error"; -import { timeShortcuts } from "discourse/lib/time-shortcut"; -import discourseComputed from "discourse-common/utils/decorators"; - -export default Controller.extend(ModalFunctionality, { - loading: false, - ignoredUntil: null, - ignoredUsername: null, - - @discourseComputed - timeShortcuts() { - const timezone = this.currentUser.user_option.timezone; - const shortcuts = timeShortcuts(timezone); - return [ - shortcuts.laterToday(), - shortcuts.tomorrow(), - shortcuts.laterThisWeek(), - shortcuts.thisWeekend(), - shortcuts.monday(), - shortcuts.twoWeeks(), - shortcuts.nextMonth(), - shortcuts.twoMonths(), - shortcuts.threeMonths(), - shortcuts.fourMonths(), - shortcuts.sixMonths(), - shortcuts.oneYear(), - shortcuts.forever(), - ]; - }, - - actions: { - ignore() { - if (!this.ignoredUntil || !this.ignoredUsername) { - this.flash( - I18n.t("user.user_notifications.ignore_duration_time_frame_required"), - "error" - ); - return; - } - this.set("loading", true); - User.findByUsername(this.ignoredUsername).then((user) => { - user - .updateNotificationLevel({ - level: "ignore", - expiringAt: this.ignoredUntil, - actingUser: this.model, - }) - .then(() => { - this.onUserIgnored(this.ignoredUsername); - this.send("closeModal"); - }) - .catch(popupAjaxError) - .finally(() => this.set("loading", false)); - }); - }, - - updateIgnoredUsername(selected) { - this.set("ignoredUsername", selected.firstObject); - }, - }, -}); diff --git a/app/assets/javascripts/discourse/app/templates/modal/ignore-duration-with-username.hbs b/app/assets/javascripts/discourse/app/templates/modal/ignore-duration-with-username.hbs deleted file mode 100644 index 550fa5b9a64..00000000000 --- a/app/assets/javascripts/discourse/app/templates/modal/ignore-duration-with-username.hbs +++ /dev/null @@ -1,32 +0,0 @@ - -
- - -
- -

{{i18n "user.user_notifications.ignore_duration_note"}}

-
- - \ No newline at end of file