diff --git a/javascripts/discourse/api-initializers/modify-topic-list.js b/javascripts/discourse/api-initializers/modify-topic-list.js index 1371f35..162dca1 100644 --- a/javascripts/discourse/api-initializers/modify-topic-list.js +++ b/javascripts/discourse/api-initializers/modify-topic-list.js @@ -1,7 +1,29 @@ +import HeaderLikesCell from "discourse/components/topic-list/header/likes-cell"; +import ItemLikesCell from "discourse/components/topic-list/item/likes-cell"; import { apiInitializer } from "discourse/lib/api"; +import { withSilencedDeprecations } from "discourse-common/lib/deprecated"; export default apiInitializer("0.8", (api) => { - api.modifyClass("component:topic-list", { - showLikes: true, + api.registerValueTransformer("topic-list-columns", ({ value: columns }) => { + if (!columns.has("likes")) { + columns.add( + "likes", + { + header: HeaderLikesCell, + item: ItemLikesCell, + }, + { + after: "replies", + before: "views", + } + ); + } + return columns; + }); + + withSilencedDeprecations("discourse.hbr-topic-list-overrides", () => { + api.modifyClass("component:topic-list", { + showLikes: true, + }); }); }); diff --git a/spec/system/like_column_spec.rb b/spec/system/like_column_spec.rb new file mode 100644 index 0000000..1b95e0c --- /dev/null +++ b/spec/system/like_column_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +RSpec.describe "Like column", type: :system do + fab!(:theme) { upload_theme_component } + fab!(:category) + fab!(:topics) do + Fabricate + .times(3, :topic_with_op, category: category) + .tap { |topics| topics.each { |t| Fabricate(:like, post: t.first_post) } } + end + + it "renders the likes column" do + visit "/latest" + + expect(page).to have_css("th.topic-list-data.likes", count: 1) + expect(page).to have_css("td.topic-list-data.likes", text: "1", count: 3) + end +end