Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add a new behavior transformer to topic list item click (#31653)

Amanda Alves Branquinhof9e4ac94f5c3
diff --git a/app/assets/javascripts/discourse/app/components/topic-list/item.gjs b/app/assets/javascripts/discourse/app/components/topic-list/item.gjs
index 9aa99867ffa..03ad751324d 100644
--- a/app/assets/javascripts/discourse/app/components/topic-list/item.gjs
+++ b/app/assets/javascripts/discourse/app/components/topic-list/item.gjs
@@ -19,7 +19,10 @@ import discourseTags from "discourse/helpers/discourse-tags";
import formatDate from "discourse/helpers/format-date";
import topicFeaturedLink from "discourse/helpers/topic-featured-link";
import { wantsNewWindow } from "discourse/lib/intercept-click";
-import { applyValueTransformer } from "discourse/lib/transformer";
+import {
+ applyBehaviorTransformer,
+ applyValueTransformer,
+} from "discourse/lib/transformer";
import DiscourseURL from "discourse/lib/url";
import { i18n } from "discourse-i18n";
@@ -134,35 +137,45 @@ export default class Item extends Component {
@action
click(e) {
- if (
- e.target.classList.contains("raw-topic-link") ||
- e.target.classList.contains("post-activity") ||
- e.target.classList.contains("badge-posts")
- ) {
- if (wantsNewWindow(e)) {
- return;
- }
-
- e.preventDefault();
- this.navigateToTopic(this.args.topic, e.target.href);
- return;
- }
-
- // make full row click target on mobile, due to size constraints
- if (
- this.site.mobileView &&
- e.target.matches(
- ".topic-list-data, .main-link, .right, .topic-item-stats, .topic-item-stats__category-tags, .discourse-tags"
- )
- ) {
- if (wantsNewWindow(e)) {
- return;
+ applyBehaviorTransformer(
+ "topic-list-item-click",
+ () => {
+ if (
+ e.target.classList.contains("raw-topic-link") ||
+ e.target.classList.contains("post-activity") ||
+ e.target.classList.contains("badge-posts")
+ ) {
+ if (wantsNewWindow(e)) {
+ return;
+ }
+
+ e.preventDefault();
+ this.navigateToTopic(this.args.topic, e.target.href);
+ return;
+ }
+
+ // make full row click target on mobile, due to size constraints
+ if (
+ this.site.mobileView &&
+ e.target.matches(
+ ".topic-list-data, .main-link, .right, .topic-item-stats, .topic-item-stats__category-tags, .discourse-tags"
+ )
+ ) {
+ if (wantsNewWindow(e)) {
+ return;
+ }
+
+ e.preventDefault();
+ this.navigateToTopic(this.args.topic, this.args.topic.lastUnreadUrl);
+ return;
+ }
+ },
+ {
+ topic: this.args.topic,
+ event: e,
+ navigateToTopic: this.navigateToTopic,
}
-
- e.preventDefault();
- this.navigateToTopic(this.args.topic, this.args.topic.lastUnreadUrl);
- return;
- }
+ );
}
@action
diff --git a/app/assets/javascripts/discourse/app/lib/transformer/registry.js b/app/assets/javascripts/discourse/app/lib/transformer/registry.js
index 7352ccf85b6..b1cfd1683bc 100644
--- a/app/assets/javascripts/discourse/app/lib/transformer/registry.js
+++ b/app/assets/javascripts/discourse/app/lib/transformer/registry.js
@@ -5,6 +5,7 @@ export const BEHAVIOR_TRANSFORMERS = Object.freeze([
"discovery-topic-list-load-more",
"full-page-search-load-more",
"post-menu-toggle-like-action",
+ "topic-list-item-click",
]);
export const VALUE_TRANSFORMERS = Object.freeze([