From 4c5164a816c40f39773e95115d5ec8e4ede2ad1f Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 13 Jan 2025 16:49:57 +0000 Subject: [PATCH 1/2] DEV: Update for glimmer topic-list --- .../api-initializers/modify-topic-list.js | 26 +++++++++++++++++-- spec/system/like_column_spec.rb | 18 +++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 spec/system/like_column_spec.rb diff --git a/javascripts/discourse/api-initializers/modify-topic-list.js b/javascripts/discourse/api-initializers/modify-topic-list.js index 1371f35..7e09672 100644 --- a/javascripts/discourse/api-initializers/modify-topic-list.js +++ b/javascripts/discourse/api-initializers/modify-topic-list.js @@ -1,7 +1,29 @@ import { apiInitializer } from "discourse/lib/api"; +import { withSilencedDeprecations } from "discourse-common/lib/deprecated"; +import HeaderLikesCell from "discourse/components/topic-list/header/likes-cell"; +import ItemLikesCell from "discourse/components/topic-list/item/likes-cell"; 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 From bc915d43c4014339ca32bf0b42f5b086365af649 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 13 Jan 2025 16:59:28 +0000 Subject: [PATCH 2/2] lint --- javascripts/discourse/api-initializers/modify-topic-list.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/javascripts/discourse/api-initializers/modify-topic-list.js b/javascripts/discourse/api-initializers/modify-topic-list.js index 7e09672..162dca1 100644 --- a/javascripts/discourse/api-initializers/modify-topic-list.js +++ b/javascripts/discourse/api-initializers/modify-topic-list.js @@ -1,7 +1,7 @@ -import { apiInitializer } from "discourse/lib/api"; -import { withSilencedDeprecations } from "discourse-common/lib/deprecated"; 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.registerValueTransformer("topic-list-columns", ({ value: columns }) => {