diff --git a/app/assets/javascripts/discourse/app/components/choose-message.gjs b/app/assets/javascripts/discourse/app/components/choose-message.gjs
new file mode 100644
index 00000000000..e5461e29386
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/components/choose-message.gjs
@@ -0,0 +1,80 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { fn } from "@ember/helper";
+import { on } from "@ember/modifier";
+import { action } from "@ember/object";
+import { isEmpty } from "@ember/utils";
+import { searchForTerm } from "discourse/lib/search";
+import { debounce } from "discourse-common/utils/decorators";
+import { i18n } from "discourse-i18n";
+
+export default class ChooseMessage extends Component {
+ @tracked hasSearched = false;
+ @tracked loading = false;
+ @tracked messages;
+
+ @debounce(300)
+ async debouncedSearch(title) {
+ if (isEmpty(title)) {
+ this.messages = null;
+ this.loading = false;
+ return;
+ }
+
+ const results = await searchForTerm(title, {
+ typeFilter: "private_messages",
+ searchForId: true,
+ restrictToArchetype: "private_message",
+ });
+
+ this.messages = results?.posts
+ ?.mapBy("topic")
+ .filter((topic) => topic.id !== this.args.currentTopicId);
+
+ this.loading = false;
+ }
+
+ @action
+ search(event) {
+ this.hasSearched = true;
+ this.loading = true;
+ this.args.setSelectedTopicId(null);
+ this.debouncedSearch(event.target.value);
+ }
+
+
+ {{i18n "loading"}} {{i18n "choose_message.none_found"}}
{{i18n "loading"}}
-{{else}} - {{#if this.noResults}} -{{i18n "choose_message.none_found"}}
- {{else}} - {{#each this.messages as |m|}} - - {{/each}} - {{/if}} -{{/if}} \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/choose-message.js b/app/assets/javascripts/discourse/app/components/choose-message.js deleted file mode 100644 index d8f00087a4e..00000000000 --- a/app/assets/javascripts/discourse/app/components/choose-message.js +++ /dev/null @@ -1,66 +0,0 @@ -import Component from "@ember/component"; -import { action, get } from "@ember/object"; -import { next } from "@ember/runloop"; -import { isEmpty } from "@ember/utils"; -import { observes } from "@ember-decorators/object"; -import $ from "jquery"; -import { searchForTerm } from "discourse/lib/search"; -import { debounce } from "discourse-common/utils/decorators"; - -export default class ChooseMessage extends Component { - loading = null; - noResults = null; - messages = null; - - @observes("messageTitle") - messageTitleChanged() { - this.setProperties({ - loading: true, - noResults: true, - selectedTopicId: null, - }); - this.search(this.messageTitle); - } - - @observes("messages") - messagesChanged() { - const messages = this.messages; - if (messages) { - this.set("noResults", messages.length === 0); - } - this.set("loading", false); - } - - @debounce(300) - search(title) { - if (isEmpty(title)) { - this.setProperties({ messages: null, loading: false }); - return; - } - - searchForTerm(title, { - typeFilter: "private_messages", - searchForId: true, - restrictToArchetype: "private_message", - }).then((results) => { - if (results?.posts?.length) { - this.set( - "messages", - results.posts - .mapBy("topic") - .filter((t) => t.get("id") !== this.currentTopicId) - ); - } else { - this.setProperties({ messages: null, loading: false }); - } - }); - } - - @action - chooseMessage(message, event) { - event?.preventDefault(); - const messageId = get(message, "id"); - this.set("selectedTopicId", messageId); - next(() => $(`#choose-message-${messageId}`).prop("checked", "true")); - } -} diff --git a/app/assets/javascripts/discourse/app/components/modal/move-to-topic.hbs b/app/assets/javascripts/discourse/app/components/modal/move-to-topic.hbs index c06d7fe910c..607827a9766 100644 --- a/app/assets/javascripts/discourse/app/components/modal/move-to-topic.hbs +++ b/app/assets/javascripts/discourse/app/components/modal/move-to-topic.hbs @@ -70,7 +70,7 @@