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:
parent
a8292d25f8
commit
161256eef8
|
@ -33,6 +33,7 @@ function entranceDate(dt, showTime) {
|
||||||
export default Component.extend(CleansUp, {
|
export default Component.extend(CleansUp, {
|
||||||
router: service(),
|
router: service(),
|
||||||
session: service(),
|
session: service(),
|
||||||
|
historyStore: service(),
|
||||||
elementId: "topic-entrance",
|
elementId: "topic-entrance",
|
||||||
classNameBindings: ["visible::hidden"],
|
classNameBindings: ["visible::hidden"],
|
||||||
topic: null,
|
topic: null,
|
||||||
|
@ -166,10 +167,7 @@ export default Component.extend(CleansUp, {
|
||||||
},
|
},
|
||||||
|
|
||||||
_jumpTo(destination) {
|
_jumpTo(destination) {
|
||||||
this.session.set("lastTopicIdViewed", {
|
this.historyStore.set("lastTopicIdViewed", this.topic.id);
|
||||||
topicId: this.topic.id,
|
|
||||||
historyUuid: this.router.location.getState?.().uuid,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.cleanUp();
|
this.cleanUp();
|
||||||
DiscourseURL.routeTo(destination);
|
DiscourseURL.routeTo(destination);
|
||||||
|
|
|
@ -38,8 +38,7 @@ export function showEntrance(e) {
|
||||||
|
|
||||||
export function navigateToTopic(topic, href) {
|
export function navigateToTopic(topic, href) {
|
||||||
const owner = getOwner(this);
|
const owner = getOwner(this);
|
||||||
const router = owner.lookup("service:router");
|
const historyStore = owner.lookup("service:history-store");
|
||||||
const session = owner.lookup("service:session");
|
|
||||||
const siteSettings = owner.lookup("service:site-settings");
|
const siteSettings = owner.lookup("service:site-settings");
|
||||||
const appEvents = owner.lookup("service:appEvents");
|
const appEvents = owner.lookup("service:appEvents");
|
||||||
|
|
||||||
|
@ -49,10 +48,7 @@ export function navigateToTopic(topic, href) {
|
||||||
appEvents.trigger("header:update-topic", topic);
|
appEvents.trigger("header:update-topic", topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
session.set("lastTopicIdViewed", {
|
historyStore.set("lastTopicIdViewed", topic.id);
|
||||||
topicId: topic.id,
|
|
||||||
historyUuid: router.location.getState?.().uuid,
|
|
||||||
});
|
|
||||||
|
|
||||||
DiscourseURL.routeTo(href || topic.get("url"));
|
DiscourseURL.routeTo(href || topic.get("url"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -60,6 +56,7 @@ export function navigateToTopic(topic, href) {
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
router: service(),
|
router: service(),
|
||||||
|
historyStore: service(),
|
||||||
tagName: "tr",
|
tagName: "tr",
|
||||||
classNameBindings: [":topic-list-item", "unboundClassNames", "topic.visited"],
|
classNameBindings: [":topic-list-item", "unboundClassNames", "topic.visited"],
|
||||||
attributeBindings: ["data-topic-id", "role", "ariaLevel:aria-level"],
|
attributeBindings: ["data-topic-id", "role", "ariaLevel:aria-level"],
|
||||||
|
@ -354,15 +351,11 @@ export default Component.extend({
|
||||||
|
|
||||||
_highlightIfNeeded: on("didInsertElement", function () {
|
_highlightIfNeeded: on("didInsertElement", function () {
|
||||||
// highlight the last topic viewed
|
// highlight the last topic viewed
|
||||||
const lastViewedTopicInfo = this.session.get("lastTopicIdViewed");
|
const lastViewedTopicId = this.historyStore.get("lastTopicIdViewed");
|
||||||
|
const isLastViewedTopic = lastViewedTopicId === this.topic.id;
|
||||||
const isLastViewedTopic =
|
|
||||||
lastViewedTopicInfo?.topicId === this.topic.id &&
|
|
||||||
lastViewedTopicInfo?.historyUuid ===
|
|
||||||
this.router.location.getState?.().uuid;
|
|
||||||
|
|
||||||
if (isLastViewedTopic) {
|
if (isLastViewedTopic) {
|
||||||
this.session.set("lastTopicIdViewed", null);
|
this.historyStore.delete("lastTopicIdViewed");
|
||||||
this.highlight({ isLastViewedTopic: true });
|
this.highlight({ isLastViewedTopic: true });
|
||||||
} else if (this.get("topic.highlight")) {
|
} else if (this.get("topic.highlight")) {
|
||||||
// highlight new topics that have been loaded from the server or the one we just created
|
// highlight new topics that have been loaded from the server or the one we just created
|
||||||
|
|
Loading…
Reference in New Issue