From 291629834d2870f3c1ac71311e5e0a39340f9027 Mon Sep 17 00:00:00 2001 From: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com> Date: Thu, 27 Jul 2023 11:52:12 -0500 Subject: [PATCH] DEV: Convert `delete-topic-confirm` modal to component-based API (#22813) Screenshot 2023-07-26 at 4 19 52 PM --- .../components/modal/delete-topic-confirm.hbs | 32 ++++++++++++++++ .../components/modal/delete-topic-confirm.js | 27 ++++++++++++++ .../app/controllers/delete-topic-confirm.js | 37 ------------------- .../discourse/app/controllers/topic.js | 6 +-- .../discourse/app/services/modal.js | 1 - .../templates/modal/delete-topic-confirm.hbs | 20 ---------- 6 files changed, 61 insertions(+), 62 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/modal/delete-topic-confirm.hbs create mode 100644 app/assets/javascripts/discourse/app/components/modal/delete-topic-confirm.js delete mode 100644 app/assets/javascripts/discourse/app/controllers/delete-topic-confirm.js delete mode 100644 app/assets/javascripts/discourse/app/templates/modal/delete-topic-confirm.hbs diff --git a/app/assets/javascripts/discourse/app/components/modal/delete-topic-confirm.hbs b/app/assets/javascripts/discourse/app/components/modal/delete-topic-confirm.hbs new file mode 100644 index 00000000000..a399846da77 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/modal/delete-topic-confirm.hbs @@ -0,0 +1,32 @@ + + <:body> +

+ {{i18n + "post.controls.delete_topic_confirm_modal" + count=this.siteSettings.min_topic_views_for_delete_confirm + }} +

+ + <:footer> + + + +
\ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/modal/delete-topic-confirm.js b/app/assets/javascripts/discourse/app/components/modal/delete-topic-confirm.js new file mode 100644 index 00000000000..f7eb53f1c2d --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/modal/delete-topic-confirm.js @@ -0,0 +1,27 @@ +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"; + +// Modal that displays confirmation text when user deletes a topic +// The modal will display only if the topic exceeds a certain amount of views +export default class DeleteTopicConfirm extends Component { + @service currentUser; + @service siteSettings; + + @tracked deletingTopic = false; + @tracked flash; + + @action + async deleteTopic() { + try { + this.deletingTopic = true; + await this.args.model.topic.destroy(this.currentUser); + this.args.closeModal(); + } catch { + this.flash = I18n.t("post.controls.delete_topic_error"); + this.deletingTopic = false; + } + } +} diff --git a/app/assets/javascripts/discourse/app/controllers/delete-topic-confirm.js b/app/assets/javascripts/discourse/app/controllers/delete-topic-confirm.js deleted file mode 100644 index 423999c3c0f..00000000000 --- a/app/assets/javascripts/discourse/app/controllers/delete-topic-confirm.js +++ /dev/null @@ -1,37 +0,0 @@ -import Controller from "@ember/controller"; -import I18n from "I18n"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; -import { action } from "@ember/object"; -import discourseComputed from "discourse-common/utils/decorators"; - -// Modal that displays confirmation text when user deletes a topic -// The modal will display only if the topic exceeds a certain amount of views -export default Controller.extend(ModalFunctionality, { - deletingTopic: false, - - @discourseComputed("deletingTopic") - buttonTitle(deletingTopic) { - return deletingTopic - ? I18n.t("deleting") - : I18n.t("post.controls.delete_topic_confirm_modal_yes"); - }, - - onShow() { - this.set("deletingTopic", false); - }, - - @action - deleteTopic() { - this.set("deletingTopic", true); - - this.model - .destroy(this.currentUser) - .then(() => this.send("closeModal")) - .catch(() => { - this.flash(I18n.t("post.controls.delete_topic_error"), "error"); - this.set("deletingTopic", false); - }); - - return false; - }, -}); diff --git a/app/assets/javascripts/discourse/app/controllers/topic.js b/app/assets/javascripts/discourse/app/controllers/topic.js index 0c3830a39f5..075a0cdec6f 100644 --- a/app/assets/javascripts/discourse/app/controllers/topic.js +++ b/app/assets/javascripts/discourse/app/controllers/topic.js @@ -35,6 +35,7 @@ import { inject as service } from "@ember/service"; import showModal from "discourse/lib/show-modal"; import { spinnerHTML } from "discourse/helpers/loading-spinner"; import { BookmarkFormData } from "discourse/lib/bookmark"; +import DeleteTopicConfirmModal from "discourse/components/modal/delete-topic-confirm"; let customPostMessageCallbacks = {}; @@ -1569,10 +1570,7 @@ export default Controller.extend(bufferedProperty("model"), { }, deleteTopicModal() { - showModal("delete-topic-confirm", { - model: this.model, - title: "topic.actions.delete", - }); + this.modal.show(DeleteTopicConfirmModal, { model: { topic: this.model } }); }, retryOnRateLimit(times, promise, topicId) { diff --git a/app/assets/javascripts/discourse/app/services/modal.js b/app/assets/javascripts/discourse/app/services/modal.js index f9874aaeba4..44e9fee420d 100644 --- a/app/assets/javascripts/discourse/app/services/modal.js +++ b/app/assets/javascripts/discourse/app/services/modal.js @@ -24,7 +24,6 @@ const KNOWN_LEGACY_MODALS = [ "create-account", "create-invite-bulk", "create-invite", - "delete-topic-confirm", "delete-topic-disallowed", "download-calendar", "edit-slow-mode", diff --git a/app/assets/javascripts/discourse/app/templates/modal/delete-topic-confirm.hbs b/app/assets/javascripts/discourse/app/templates/modal/delete-topic-confirm.hbs deleted file mode 100644 index 0fb6a9682a4..00000000000 --- a/app/assets/javascripts/discourse/app/templates/modal/delete-topic-confirm.hbs +++ /dev/null @@ -1,20 +0,0 @@ - -

{{i18n - "post.controls.delete_topic_confirm_modal" - count=this.siteSettings.min_topic_views_for_delete_confirm - }}

-
- - \ No newline at end of file