DEV: Update topic-list-item focus to use history-store

This avoids the need for manually reading and checking the history uuid.
This commit is contained in:
David Taylor 2023-11-20 19:55:21 +00:00
parent a8292d25f8
commit 161256eef8
2 changed files with 8 additions and 17 deletions

View File

@ -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);

View File

@ -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