A platform for community discussion. Free, open, simple.
DEV: Update topic-list-item focus to use history-store
David Taylor161256eef850
diff --git a/app/assets/javascripts/discourse/app/components/topic-entrance.js b/app/assets/javascripts/discourse/app/components/topic-entrance.jsindex 493d426c727..e43f4762145 100644--- a/app/assets/javascripts/discourse/app/components/topic-entrance.js+++ b/app/assets/javascripts/discourse/app/components/topic-entrance.js@@ -33,6 +33,7 @@ function entranceDate(dt, showTime) {export default Component.extend(CleansUp, {router: service(),session: service(),+ historyStore: service(),elementId: "topic-entrance",classNameBindings: ["visible::hidden"],topic: null,@@ -166,10 +167,7 @@ export default Component.extend(CleansUp, {},_jumpTo(destination) {- this.session.set("lastTopicIdViewed", {- topicId: this.topic.id,- historyUuid: this.router.location.getState?.().uuid,- });+ this.historyStore.set("lastTopicIdViewed", this.topic.id);this.cleanUp();DiscourseURL.routeTo(destination);diff --git a/app/assets/javascripts/discourse/app/components/topic-list-item.js b/app/assets/javascripts/discourse/app/components/topic-list-item.jsindex 04526a19ba6..d530914cb8f 100644--- a/app/assets/javascripts/discourse/app/components/topic-list-item.js+++ b/app/assets/javascripts/discourse/app/components/topic-list-item.js@@ -38,8 +38,7 @@ export function showEntrance(e) {export function navigateToTopic(topic, href) {const owner = getOwner(this);- const router = owner.lookup("service:router");- const session = owner.lookup("service:session");+ const historyStore = owner.lookup("service:history-store");const siteSettings = owner.lookup("service:site-settings");const appEvents = owner.lookup("service:appEvents");@@ -49,10 +48,7 @@ export function navigateToTopic(topic, href) {appEvents.trigger("header:update-topic", topic);}- session.set("lastTopicIdViewed", {- topicId: topic.id,- historyUuid: router.location.getState?.().uuid,- });+ historyStore.set("lastTopicIdViewed", topic.id);DiscourseURL.routeTo(href || topic.get("url"));return false;@@ -60,6 +56,7 @@ export function navigateToTopic(topic, href) {export default Component.extend({router: service(),+ historyStore: service(),tagName: "tr",classNameBindings: [":topic-list-item", "unboundClassNames", "topic.visited"],attributeBindings: ["data-topic-id", "role", "ariaLevel:aria-level"],@@ -354,15 +351,11 @@ export default Component.extend({_highlightIfNeeded: on("didInsertElement", function () {// highlight the last topic viewed- const lastViewedTopicInfo = this.session.get("lastTopicIdViewed");-- const isLastViewedTopic =- lastViewedTopicInfo?.topicId === this.topic.id &&- lastViewedTopicInfo?.historyUuid ===- this.router.location.getState?.().uuid;+ const lastViewedTopicId = this.historyStore.get("lastTopicIdViewed");+ const isLastViewedTopic = lastViewedTopicId === this.topic.id;if (isLastViewedTopic) {- this.session.set("lastTopicIdViewed", null);+ this.historyStore.delete("lastTopicIdViewed");this.highlight({ isLastViewedTopic: true });} else if (this.get("topic.highlight")) {// highlight new topics that have been loaded from the server or the one we just created