Skip to content

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

DEV: Drop (almost)-unused `TopicEntrance` component (#41424)

David Taylorf3b72660ace9
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index ea3017cca57..3f6a803c6c6 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -6071,8 +6071,6 @@ en:
no_group_messages_title: "No group messages found"
topic_entrance:
- sr_jump_top_button: "Jump to the first post - %{date}"
- sr_jump_bottom_button: "Jump to the last post - %{date}"
jump_top_button_title: "Jump to the first post"
jump_bottom_button_title: "Jump to the last post"
fullscreen_table:
diff --git a/frontend/discourse/app/components/basic-topic-list.gjs b/frontend/discourse/app/components/basic-topic-list.gjs
index da2d3bc7ef3..7bb5fc0ea75 100644
--- a/frontend/discourse/app/components/basic-topic-list.gjs
+++ b/frontend/discourse/app/components/basic-topic-list.gjs
@@ -1,16 +1,12 @@
/* eslint-disable ember/no-classic-components, ember/no-observers, ember/require-tagless-components */
import Component from "@ember/component";
import { computed, set } from "@ember/object";
-import { service } from "@ember/service";
import { observes } from "@ember-decorators/object";
import List from "discourse/components/topic-list/list";
-import domUtils from "discourse/lib/dom-utils";
import DConditionalLoadingSpinner from "discourse/ui-kit/d-conditional-loading-spinner";
import { i18n } from "discourse-i18n";
export default class BasicTopicList extends Component {
- @service site;
-
init() {
super.init(...arguments);
const topicList = this.topicList;
@@ -62,38 +58,6 @@ export default class BasicTopicList extends Component {
);
}
- click(e) {
- // Mobile basic-topic-list doesn't use the `topic-list-item` view so
- // the event for the topic entrance is never wired up.
- if (this.site.desktopView) {
- return;
- }
-
- let target = e.target;
- if (target.closest(".posts-map")) {
- const topicId = target.closest("tr")?.getAttribute("data-topic-id");
- if (topicId) {
- if (target.tagName !== "A") {
- const link = target.querySelector("a") || target.closest("a");
- if (link) {
- target = link;
- } else {
- return false;
- }
- }
-
- const topic = this.topics.find(
- (value) => value.id === parseInt(topicId, 10)
- );
- this.appEvents.trigger("topic-entrance:show", {
- topic,
- position: domUtils.offset(target),
- });
- }
- return false;
- }
- }
-
<template>
<DConditionalLoadingSpinner @condition={{this.loading}}>
{{#if this.topics}}
diff --git a/frontend/discourse/app/components/featured-topic.gjs b/frontend/discourse/app/components/featured-topic.gjs
index 1015b2dff50..5edecf4fde4 100644
--- a/frontend/discourse/app/components/featured-topic.gjs
+++ b/frontend/discourse/app/components/featured-topic.gjs
@@ -6,23 +6,12 @@ import {
classNameBindings,
} from "@ember-decorators/component";
import TopicPostBadges from "discourse/components/topic-post-badges";
-import domUtils from "discourse/lib/dom-utils";
import dAgeWithTooltip from "discourse/ui-kit/helpers/d-age-with-tooltip";
import TopicStatus from "./topic-status";
@classNameBindings(":featured-topic")
@attributeBindings("topic.id:data-topic-id")
export default class FeaturedTopic extends Component {
- click(e) {
- if (e.target.closest(".last-posted-at")) {
- this.appEvents.trigger("topic-entrance:show", {
- topic: this.topic,
- position: domUtils.offset(e.target),
- });
- return false;
- }
- }
-
<template>
<TopicStatus @topic={{this.topic}} @disableActions={{true}} />
<a href={{this.topic.lastUnreadUrl}} class="title">{{trustHTML
diff --git a/frontend/discourse/app/components/mobile-category-topic.gjs b/frontend/discourse/app/components/mobile-category-topic.gjs
index 80665379871..205e67ca23e 100644
--- a/frontend/discourse/app/components/mobile-category-topic.gjs
+++ b/frontend/discourse/app/components/mobile-category-topic.gjs
@@ -4,31 +4,12 @@ import { classNameBindings, tagName } from "@ember-decorators/component";
import PostCountOrBadges from "discourse/components/topic-list/post-count-or-badges";
import TopicStatus from "discourse/components/topic-status";
import coldAgeClass from "discourse/helpers/cold-age-class";
-import domUtils from "discourse/lib/dom-utils";
import dAgeWithTooltip from "discourse/ui-kit/helpers/d-age-with-tooltip";
import dTopicLink from "discourse/ui-kit/helpers/d-topic-link";
-export function showEntrance(e) {
- let target = e.target;
-
- if (target.closest(".posts-map")) {
- if (target.tagName !== "A") {
- target = target.querySelector("a") || target;
- }
-
- this.appEvents.trigger("topic-entrance:show", {
- topic: this.topic,
- position: domUtils.offset(target),
- });
- return false;
- }
-}
-
@tagName("tr")
@classNameBindings(":category-topic-link", "topic.archived", "topic.visited")
export default class MobileCategoryTopic extends Component {
- click = showEntrance;
-
<template>
<td class="main-link">
<div class="topic-inset">
diff --git a/frontend/discourse/app/components/topic-entrance.gjs b/frontend/discourse/app/components/topic-entrance.gjs
deleted file mode 100644
index 2ee97da4091..00000000000
--- a/frontend/discourse/app/components/topic-entrance.gjs
+++ /dev/null
@@ -1,233 +0,0 @@
-/* eslint-disable ember/no-classic-components, ember/no-jquery, ember/require-tagless-components */
-import Component from "@ember/component";
-import { action, computed } from "@ember/object";
-import { scheduleOnce } from "@ember/runloop";
-import { service } from "@ember/service";
-import { trustHTML } from "@ember/template";
-import { classNameBindings } from "@ember-decorators/component";
-import { on } from "@ember-decorators/object";
-import $ from "jquery";
-import { bind } from "discourse/lib/decorators";
-import DiscourseURL from "discourse/lib/url";
-import DButton from "discourse/ui-kit/d-button";
-import dIcon from "discourse/ui-kit/helpers/d-icon";
-import { i18n } from "discourse-i18n";
-
-function entranceDate(dt, showTime) {
- const today = new Date();
-
- if (dt.toDateString() === today.toDateString()) {
- return moment(dt).format(i18n("dates.time"));
- }
-
- if (dt.getYear() === today.getYear()) {
- // No year
- return moment(dt).format(
- showTime
- ? i18n("dates.long_date_without_year_with_linebreak")
- : i18n("dates.long_no_year_no_time")
- );
- }
-
- return moment(dt).format(
- showTime
- ? i18n("dates.long_date_with_year_with_linebreak")
- : i18n("dates.long_date_with_year_without_time")
- );
-}
-
-@classNameBindings("visible::hidden")
-export default class TopicEntrance extends Component {
- @service historyStore;
-
- elementId = "topic-entrance";
- topic = null;
- visible = null;
- _position = null;
- _originalActiveElement = null;
- _activeButton = null;
-
- @computed("topic.created_at")
- get createdDate() {
- return new Date(this.topic?.created_at);
- }
-
- @computed("topic.bumped_at")
- get bumpedDate() {
- return new Date(this.topic?.bumped_at);
- }
-
- @computed("createdDate", "bumpedDate")
- get showTime() {
- return (
- this.bumpedDate.getTime() - this.createdDate.getTime() <
- 1000 * 60 * 60 * 24 * 2
- );
- }
-
- @computed("createdDate", "showTime")
- get topDate() {
- return entranceDate(this.createdDate, this.showTime);
- }
-
- @computed("bumpedDate", "showTime")
- get bottomDate() {
- return entranceDate(this.bumpedDate, this.showTime);
- }
-
- @on("didInsertElement")
- _inserted() {
- this.appEvents.on("topic-entrance:show", this, "_show");
- this.appEvents.on("dom:clean", this, this.cleanUp);
- }
-
- @on("didDestroyElement")
- _destroyed() {
- this.appEvents.off("dom:clean", this, this.cleanUp);
- }
-
- _setCSS() {
- const pos = this._position;
- const $self = $(this.element);
- const width = $self.width();
- const height = $self.height();
- pos.left = parseInt(pos.left, 10) - width / 2;
- pos.top = parseInt(pos.top, 10) - height / 2;
-
- const windowWidth = $(window).width();
- if (pos.left + width > windowWidth) {
- pos.left = windowWidth - width - 15;
- }
- $self.css(pos);
- }
-
- @bind
- _escListener(e) {
- if (e.key === "Escape") {
- this.cleanUp();
- } else if (e.key === "Tab") {
- if (this._activeButton === "top") {
- this._jumpBottomButton().focus();
- this._activeButton = "bottom";
- e.preventDefault();
- } else if (this._activeButton === "bottom") {
- this._jumpTopButton().focus();
- this._activeButton = "top";
- e.preventDefault();
- }
- }
- }
-
- _jumpTopButton() {
- return this.element.querySelector(".jump-top");
- }
-
- _jumpBottomButton() {
- return this.element.querySelector(".jump-bottom");
- }
-
- _setupEscListener() {
- document.body.addEventListener("keydown", this._escListener);
- }
-
- _removeEscListener() {
- document.body.removeEventListener("keydown", this._escListener);
- }
-
- _trapFocus() {
- this._originalActiveElement = document.activeElement;
- this._jumpTopButton().focus();
- this._activeButton = "top";
- }
-
- _releaseFocus() {
- if (this._originalActiveElement) {
- this._originalActiveElement.focus();
- this._originalActiveElement = null;
- }
- }
-
- _applyDomChanges() {
- this._setCSS();
- this._setupEscListener();
- this._trapFocus();
- }
-
- _show(data) {
- this._position = data.position;
-
- this.setProperties({ topic: data.topic, visible: true });
-
- scheduleOnce("afterRender", this, this._applyDomChanges);
-
- $("html")
- .off("mousedown.topic-entrance")
- .on("mousedown.topic-entrance", (e) => {
- const $target = $(e.target);
- if (
- $target.prop("id") === "topic-entrance" ||
- $(this.element).has($target).length !== 0
- ) {
- return;
- }
- this.cleanUp();
- });
- }
-
- cleanUp() {
- this.setProperties({ topic: null, visible: false });
- $("html").off("mousedown.topic-entrance");
- this._removeEscListener();
- this._releaseFocus();
- }
-
- willDestroyElement() {
- super.willDestroyElement(...arguments);
- this.appEvents.off("topic-entrance:show", this, "_show");
- }
-
- _jumpTo(destination) {
- this.historyStore.set("lastTopicIdViewed", this.topic.id);
-
- this.cleanUp();
- DiscourseURL.routeTo(destination);
- }
-
- @action
- enterTop() {
- this._jumpTo(this.get("topic.url"));
- }
-
- @action
- enterBottom() {
- this._jumpTo(this.get("topic.lastPostUrl"));
- }
-
- <template>
- <DButton
- @action={{this.enterTop}}
- @translatedAriaLabel={{i18n
- "topic_entrance.sr_jump_top_button"
- date=this.topDate
- }}
- title={{i18n "topic_entrance.jump_top_button_title"}}
- class="btn-default full jump-top"
- >
- {{dIcon "backward-step"}}
- {{trustHTML this.topDate}}
- </DButton>
-
- <DButton
- @action={{this.enterBottom}}
- @translatedAriaLabel={{i18n
- "topic_entrance.sr_jump_bottom_button"
- date=this.bottomDate
- }}
- title={{i18n "topic_entrance.jump_bottom_button_title"}}
- class="btn-default full jump-bottom"
- >
- {{trustHTML this.bottomDate}}
- {{dIcon "forward-step"}}
- </DButton>
- </template>
-}
diff --git a/frontend/discourse/app/components/topic-list/featured-topic.gjs b/frontend/discourse/app/components/topic-list/featured-topic.gjs
index 61fbe271577..3f5d54c8ee5 100644
--- a/frontend/discourse/app/components/topic-list/featured-topic.gjs
+++ b/frontend/discourse/app/components/topic-list/featured-topic.gjs
@@ -1,20 +1,8 @@
-import { on } from "@ember/modifier";
import { trustHTML } from "@ember/template";
import TopicPostBadges from "discourse/components/topic-post-badges";
import TopicStatus from "discourse/components/topic-status";
-import { wantsNewWindow } from "discourse/lib/intercept-click";
import dAgeWithTooltip from "discourse/ui-kit/helpers/d-age-with-tooltip";
-const onTimestampClick = function (event) {
- if (wantsNewWindow(event)) {
- // Allow opening the link in a new tab/window
- event.stopPropagation();
- } else {
- // Otherwise only display the TopicEntrance component
- event.preventDefault();
- }
-};
-
const FeaturedTopic = <template>
<div data-topic-id={{@topic.id}} class="featured-topic --glimmer">
<TopicStatus @topic={{@topic}} @context="topic-list" />
@@ -29,11 +17,9 @@ const FeaturedTopic = <template>
@url={{@topic.lastUnreadUrl}}
/>
- <a
- {{on "click" onTimestampClick}}
- href={{@topic.lastPostUrl}}
- class="last-posted-at"
- >{{dAgeWithTooltip @topic.last_posted_at}}</a>
+ <a href={{@topic.lastPostUrl}} class="last-posted-at">{{dAgeWithTooltip
+ @topic.last_posted_at
+ }}</a>
</div>
</template>;
diff --git a/frontend/discourse/app/templates/application.gjs b/frontend/discourse/app/templates/application.gjs
index e5ad1e0bf53..d77457cbad3 100644
--- a/frontend/discourse/app/templates/application.gjs
+++ b/frontend/discourse/app/templates/application.gjs
@@ -23,7 +23,6 @@ import PwaInstallBanner from "discourse/components/pwa-install-banner";
import RenderGlimmerContainer from "discourse/components/render-glimmer-container";
import SidebarWrapper from "discourse/components/sidebar-wrapper";
import SoftwareUpdatePrompt from "discourse/components/software-update-prompt";
-import TopicEntrance from "discourse/components/topic-entrance";
import WelcomeBanner from "discourse/components/welcome-banner";
import DialogHolder from "discourse/dialog-holder/components/dialog-holder";
import DMenus from "discourse/float-kit/components/d-menus";
@@ -176,7 +175,6 @@ export default <template>
<ModalContainer />
<DialogHolder />
- <TopicEntrance />
<ComposerContainer />
<RenderGlimmerContainer />