FIX: Rerender related topics correctly when topic changes (#100)

* FIX: Rerender related topics correctly when topic changes


Co-authored-by: Rafael dos Santos Silva <xfalcox@gmail.com>
This commit is contained in:
David Taylor 2023-07-13 20:34:02 +01:00 committed by GitHub
parent 5e3f4e1b78
commit 48d880d3c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 15 deletions

View File

@ -1,4 +1,4 @@
<div>
<div class="related-topics">
<h3 id="related-topics-title" class="related-topics-title">
{{i18n "discourse_ai.related_topics.title"}}
</h3>

View File

@ -1,15 +1,16 @@
export default {
shouldRender(args) {
import Component from "@glimmer/component";
import { inject as service } from "@ember/service";
export default class extends Component {
static shouldRender(args) {
return (args.model.related_topics?.length || 0) > 0;
},
setupComponent(args, component) {
if (component.model.related_topics) {
component.set(
"relatedTopics",
component.model.related_topics.map((topic) =>
this.store.createRecord("topic", topic)
)
);
}
},
};
}
@service store;
get relatedTopics() {
return this.args.outletArgs.model.related_topics.map((topic) =>
this.store.createRecord("topic", topic)
);
}
}

View File

@ -0,0 +1,3 @@
.related-topics {
margin: 4.5em 0 1em;
}

View File

@ -16,6 +16,8 @@ register_asset "stylesheets/modules/ai-helper/common/ai-helper.scss"
register_asset "stylesheets/modules/ai-bot/common/bot-replies.scss"
register_asset "stylesheets/modules/embeddings/common/semantic-related-topics.scss"
module ::DiscourseAi
PLUGIN_NAME = "discourse-ai"
end