From f57878f20f3d3131fbd329b582b0447a4a3f9c03 Mon Sep 17 00:00:00 2001 From: Kris Date: Tue, 4 May 2021 16:40:42 -0400 Subject: [PATCH] FEATURE: Add more class names to latest-topic-list-item (#12933) --- .../app/components/latest-topic-list-item.js | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/latest-topic-list-item.js b/app/assets/javascripts/discourse/app/components/latest-topic-list-item.js index 96fc9310b2e..d6cb6347a51 100644 --- a/app/assets/javascripts/discourse/app/components/latest-topic-list-item.js +++ b/app/assets/javascripts/discourse/app/components/latest-topic-list-item.js @@ -3,15 +3,11 @@ import { showEntrance, } from "discourse/components/topic-list-item"; import Component from "@ember/component"; +import discourseComputed from "discourse-common/utils/decorators"; export default Component.extend({ attributeBindings: ["topic.id:data-topic-id"], - classNameBindings: [ - ":latest-topic-list-item", - "topic.archived", - "topic.visited", - "topic.pinned", - ], + classNameBindings: [":latest-topic-list-item", "unboundClassNames"], showEntrance, navigateToTopic, @@ -27,4 +23,27 @@ export default Component.extend({ // Can be overwritten by plugins to handle clicks on other parts of the row unhandledRowClick() {}, + + @discourseComputed("topic") + unboundClassNames(topic) { + let classes = []; + + if (topic.get("category")) { + classes.push("category-" + topic.get("category.fullSlug")); + } + + if (topic.get("tags")) { + topic.get("tags").forEach((tagName) => classes.push("tag-" + tagName)); + } + + ["liked", "archived", "bookmarked", "pinned", "closed", "visited"].forEach( + (name) => { + if (topic.get(name)) { + classes.push(name); + } + } + ); + + return classes.join(" "); + }, });