mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
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, {
|
||||
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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user