UX: make entire topic card clickable

This commit is contained in:
awesomerobot
2025-05-19 15:56:29 -04:00
parent 90eae2d3f1
commit 5624f366a4
2 changed files with 42 additions and 0 deletions
@@ -0,0 +1,41 @@
import { apiInitializer } from "discourse/lib/api";
import { wantsNewWindow } from "discourse/lib/intercept-click";
export default apiInitializer((api) => {
api.registerBehaviorTransformer(
"topic-list-item-click",
({ context, next }) => {
const event = context.event;
const target = event.target;
const topic = context.topic;
const excludedSelectors = [
"a:not(.title)",
"button",
".bulk-select",
".topic-category-data",
];
const isExcluded = excludedSelectors.some((selector) =>
target.closest(selector)
);
if (isExcluded) {
return next();
}
const mainLink = target.closest(".title, .main-link, .topic-list-item");
if (mainLink) {
if (wantsNewWindow(event)) {
window.open(topic.lastUnreadUrl, "_blank");
} else {
event.preventDefault();
context.navigateToTopic(topic, topic.lastUnreadUrl);
}
return;
}
next();
}
);
});
+1
View File
@@ -359,6 +359,7 @@
}
.topic-list-item {
cursor: pointer;
background: var(--d-content-background);
box-shadow: 0 0 12px 1px var(--topic-card-shadow);