DEV: Use topic-list-item-class transformer (#321)

…to replace a deprecated topic-list-item customization
This commit is contained in:
Jarek Radosz 2024-12-03 15:09:43 +01:00 committed by GitHub
parent 41a8789ec3
commit 024d9dd70f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,18 +1,36 @@
import TopicListItem from "discourse/components/topic-list-item"; import TopicListItem from "discourse/components/topic-list-item";
import { withPluginApi } from "discourse/lib/plugin-api";
import { withSilencedDeprecations } from "discourse-common/lib/deprecated";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
export default { export default {
name: "add-topic-list-class", name: "add-topic-list-class",
initialize() { initialize() {
TopicListItem.reopen({ withPluginApi("1.39.0", (api) => {
@discourseComputed() // TODO: cvx - remove after the glimmer topic list transition
unboundClassNames() { withSilencedDeprecations("discourse.hbr-topic-list-overrides", () => {
let classList = this._super(...arguments); TopicListItem.reopen({
if (this.topic.has_accepted_answer) { @discourseComputed()
classList += " status-solved"; unboundClassNames() {
let classList = this._super(...arguments);
if (this.topic.has_accepted_answer) {
classList += " status-solved";
}
return classList;
},
});
});
api.registerValueTransformer(
"topic-list-item-class",
({ value, context }) => {
if (context.topic.get("has_accepted_answer")) {
value.push("status-solved");
}
return value;
} }
return classList; );
},
}); });
}, },
}; };