DEV: Convert related-topics to gjs (#822)

This commit is contained in:
Jarek Radosz 2024-10-08 14:16:08 +02:00 committed by GitHub
parent 545500b329
commit a3c6938cb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 57 additions and 56 deletions

View File

@ -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)
);
}
<template>
<div
role="complementary"
aria-labelledby="related-topics-title"
id="related-topics"
class={{concatClass "more-topics__list" (if this.hidden "hidden")}}
>
<h3 id="related-topics-title" class="more-topics__list-title">
{{i18n "discourse_ai.related_topics.title"}}
</h3>
<div class="topics">
<BasicTopicList @topics={{this.relatedTopics}} />
</div>
</div>
</template>
}

View File

@ -1,15 +0,0 @@
<div
id="related-topics"
class="more-topics__list {{if this.hidden 'hidden'}}"
role="complementary"
aria-labelledby="related-topics-title"
{{did-insert this.registerList}}
{{will-destroy this.removeList}}
>
<h3 id="related-topics-title" class="more-topics__list-title">
{{i18n "discourse_ai.related_topics.title"}}
</h3>
<div class="topics">
<BasicTopicList @topics={{this.relatedTopics}} />
</div>
</div>

View File

@ -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);
}
}