DEV: Update modifyClass calls

- Update `controller:topic` modification to native class syntax
- Remove search-result-entry modification in favour of plugin-outlet-based solution
This commit is contained in:
David Taylor 2024-12-02 11:28:41 +00:00
parent 0abd4b1244
commit 593e8dc2a5
No known key found for this signature in database
GPG Key ID: 46904C18B1D3F434
3 changed files with 35 additions and 34 deletions

View File

@ -1,10 +1,16 @@
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import icon from "discourse-common/helpers/d-icon"; import icon from "discourse-common/helpers/d-icon";
import i18n from "discourse-common/helpers/i18n"; import i18n from "discourse-common/helpers/i18n";
function addResultClass(element) {
element.closest(".fps-result")?.classList.add("ai-result");
}
const SearchResultDecoration = <template> const SearchResultDecoration = <template>
<div <div
class="ai-result__icon" class="ai-result__icon"
title={{i18n "discourse_ai.embeddings.ai_generated_result"}} title={{i18n "discourse_ai.embeddings.ai_generated_result"}}
{{didInsert addResultClass}}
> >
{{icon "discourse-sparkles"}} {{icon "discourse-sparkles"}}
</div> </div>

View File

@ -26,14 +26,16 @@ function attachHeaderIcon(api) {
function initializeAIBotReplies(api) { function initializeAIBotReplies(api) {
initializePauseButton(api); initializePauseButton(api);
api.modifyClass("controller:topic", { api.modifyClass(
pluginId: "discourse-ai", "controller:topic",
(Superclass) =>
onAIBotStreamedReply: function (data) { class extends Superclass {
onAIBotStreamedReply(data) {
streamPostText(this.model.postStream, data); streamPostText(this.model.postStream, data);
}, }
subscribe: function () {
this._super(); subscribe() {
super.subscribe();
if ( if (
this.model.isPrivateMessage && this.model.isPrivateMessage &&
@ -48,12 +50,14 @@ function initializeAIBotReplies(api) {
-2 -2
); );
} }
}, }
unsubscribe: function () {
unsubscribe() {
this.messageBus.unsubscribe("discourse-ai/ai-bot/topic/*"); this.messageBus.unsubscribe("discourse-ai/ai-bot/topic/*");
this._super(); super.unsubscribe();
}, }
}); }
);
} }
function initializePersonaDecorator(api) { function initializePersonaDecorator(api) {

View File

@ -1,9 +0,0 @@
import { apiInitializer } from "discourse/lib/api";
export default apiInitializer("1.15.0", (api) => {
api.modifyClass("component:search-result-entry", {
pluginId: "discourse-ai",
classNameBindings: ["bulkSelectEnabled", "post.generatedByAi:ai-result"],
});
});