Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions spec/system/jtech_theme_part1_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,22 @@
end
end

# The title's words sit in a span inside the link; a click on them loaded
# the whole page again instead of opening the topic in the app
it "opens a topic from its card's title without reloading the page" do
sign_in(member)
visit("/latest")
expect(page).to have_css(".jt-card")
page.execute_script("window.__jtSamePage = true")
link = find(".jt-card .raw-topic-link", text: topic.title, match: :first)
# core's current TopicLink wraps the words in a span; older ones don't
(link.has_css?("span", wait: 0) ? link.find("span", match: :first) : link).click
expect(page).to have_css("#post_1")
expect(page).to have_current_path(%r{/t/})
expect(page.evaluate_script("window.__jtSamePage === true")).to eq(true)
expect_no_theme_errors
end

# "Skip to main content", the first Tab on a page, was core's square chip
# jammed against the window's top edge, over the logo
it "rounds the skip link and keeps it off the window's edge" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { settings } from "virtual:theme";
import HeaderTopicCell from "discourse/components/topic-list/header/topic-cell";
import { apiInitializer } from "discourse/lib/api";
import type DAG from "discourse/lib/dag";
import { wantsNewWindow } from "discourse/lib/intercept-click";
import type Category from "discourse/models/category";
import type Topic from "discourse/models/topic";
import JtTopicCard, {
Expand Down Expand Up @@ -45,6 +46,8 @@ interface TopicListTransformerArgs<T> {

interface TopicListItemClickContext {
event: MouseEvent & { target: Element };
topic: Topic;
navigateToTopic: (topic: Topic, href: string) => void;
}

// Discovery lists (latest/new/top/category/tag, group + user activity), the
Expand Down Expand Up @@ -136,6 +139,21 @@ export default apiInitializer((api) => {
if (window.getSelection()?.toString()) {
return;
}
// The title's text sits in a span inside the link. Core opens the topic
// in the app only when the click lands on the link itself, and its
// click interceptor leaves raw links to the row; so a click on the
// words loaded the whole page again, every time.
const own = event.target.closest<HTMLAnchorElement>(
"a.raw-topic-link, a.post-activity, a.badge-posts"
);
if (own && own !== event.target) {
if (wantsNewWindow(event)) {
return;
}
event.preventDefault();
context.navigateToTopic(context.topic, own.href);
return;
}
if (
(event.target.closest("a, button, input, label") &&
!event.target.closest(".topic-excerpt")) ||
Expand Down
Loading