From a3c6938cb3dc3264e53be3994d200e611eac8ec4 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Tue, 8 Oct 2024 14:16:08 +0200 Subject: [PATCH] DEV: Convert related-topics to gjs (#822) --- .../topic-more-content/related-topics.gjs | 57 +++++++++++++++++++ .../topic-more-content/related-topics.hbs | 15 ----- .../topic-more-content/related-topics.js | 41 ------------- 3 files changed, 57 insertions(+), 56 deletions(-) create mode 100644 assets/javascripts/discourse/connectors/topic-more-content/related-topics.gjs delete mode 100644 assets/javascripts/discourse/connectors/topic-more-content/related-topics.hbs delete mode 100644 assets/javascripts/discourse/connectors/topic-more-content/related-topics.js diff --git a/assets/javascripts/discourse/connectors/topic-more-content/related-topics.gjs b/assets/javascripts/discourse/connectors/topic-more-content/related-topics.gjs new file mode 100644 index 00000000..77514c1f --- /dev/null +++ b/assets/javascripts/discourse/connectors/topic-more-content/related-topics.gjs @@ -0,0 +1,57 @@ +import Component from "@glimmer/component"; +import { service } from "@ember/service"; +import BasicTopicList from "discourse/components/basic-topic-list"; +import concatClass from "discourse/helpers/concat-class"; +import i18n from "discourse-common/helpers/i18n"; + +const LIST_ID = "related-topics"; + +export default class extends Component { + static shouldRender(args) { + return args.model.related_topics?.length; + } + + @service store; + @service moreTopicsPreferenceTracking; + + constructor() { + super(...arguments); + this.moreTopicsPreferenceTracking.registerTopicList({ + name: i18n("discourse_ai.related_topics.pill"), + id: LIST_ID, + icon: "discourse-sparkles", + }); + } + + willDestroy() { + super.willDestroy(...arguments); + this.moreTopicsPreferenceTracking.removeTopicList(LIST_ID); + } + + get hidden() { + return this.moreTopicsPreferenceTracking.selectedTab !== LIST_ID; + } + + get relatedTopics() { + return this.args.outletArgs.model.related_topics.map((topic) => + this.store.createRecord("topic", topic) + ); + } + + +} diff --git a/assets/javascripts/discourse/connectors/topic-more-content/related-topics.hbs b/assets/javascripts/discourse/connectors/topic-more-content/related-topics.hbs deleted file mode 100644 index 2471ab37..00000000 --- a/assets/javascripts/discourse/connectors/topic-more-content/related-topics.hbs +++ /dev/null @@ -1,15 +0,0 @@ - \ No newline at end of file diff --git a/assets/javascripts/discourse/connectors/topic-more-content/related-topics.js b/assets/javascripts/discourse/connectors/topic-more-content/related-topics.js deleted file mode 100644 index a1996dad..00000000 --- a/assets/javascripts/discourse/connectors/topic-more-content/related-topics.js +++ /dev/null @@ -1,41 +0,0 @@ -import Component from "@glimmer/component"; -import { action, computed } from "@ember/object"; -import { inject as service } from "@ember/service"; -import I18n from "I18n"; - -export default class extends Component { - static shouldRender(args) { - return (args.model.related_topics?.length || 0) > 0; - } - - @service store; - @service site; - @service moreTopicsPreferenceTracking; - - listId = "related-topics"; - - @computed("moreTopicsPreferenceTracking.selectedTab") - get hidden() { - return this.moreTopicsPreferenceTracking.selectedTab !== this.listId; - } - - get relatedTopics() { - return this.args.outletArgs.model.related_topics.map((topic) => - this.store.createRecord("topic", topic) - ); - } - - @action - registerList() { - this.moreTopicsPreferenceTracking.registerTopicList({ - name: I18n.t("discourse_ai.related_topics.pill"), - id: this.listId, - icon: "discourse-sparkles", - }); - } - - @action - removeList() { - this.moreTopicsPreferenceTracking.removeTopicList(this.listId); - } -}