FIX: Use history-store service to check isPoppedState()

The old heuristic was 'a transition to a URL (i.e. not a named route) which was not triggered by DiscourseURL'. That logic is flawed now that we're increasingly using Ember's routing methods.
This commit is contained in:
David Taylor 2023-11-20 19:19:05 +00:00
parent 161256eef8
commit 20e562bd99
5 changed files with 11 additions and 13 deletions

View File

@ -21,6 +21,7 @@ class AbstractCategoryRoute extends DiscourseRoute {
@service store;
@service topicTrackingState;
@service("search") searchService;
@service historyStore;
queryParams = queryParams;
@ -86,7 +87,7 @@ class AbstractCategoryRoute extends DiscourseRoute {
async _retrieveTopicList(category, transition, modelParams) {
const findOpts = filterQueryParams(modelParams, this.routeConfig);
const extras = { cached: this.isPoppedState(transition) };
const extras = { cached: this.historyStore.isPoppedState };
let listFilter = `c/${Category.slugFor(category)}/${category.id}`;
if (findOpts.no_subcategories) {

View File

@ -98,17 +98,18 @@ class AbstractTopicRoute extends DiscourseRoute {
@service store;
@service topicTrackingState;
@service currentUser;
@service historyStore;
queryParams = queryParams;
templateName = "discovery/list";
controllerName = "discovery/list";
async model(data, transition) {
async model(data) {
// attempt to stop early cause we need this to be called before .sync
this.screenTrack.stop();
const findOpts = filterQueryParams(data),
findExtras = { cached: this.isPoppedState(transition) };
findExtras = { cached: this.historyStore.isPoppedState };
const topicListPromise = findTopicList(
this.store,

View File

@ -65,13 +65,6 @@ const DiscourseRoute = Route.extend({
return user.id === this.currentUser.id;
},
isPoppedState(transition) {
return (
!transition._discourse_intercepted &&
(!!transition.intent.url || !!transition.queryParamsOnly)
);
},
});
export default DiscourseRoute;

View File

@ -26,6 +26,7 @@ export default class TagShowRoute extends DiscourseRoute {
@service store;
@service topicTrackingState;
@service("search") searchService;
@service historyStore;
queryParams = queryParams;
controllerName = "discovery/list";
@ -119,7 +120,7 @@ export default class TagShowRoute extends DiscourseRoute {
filter,
filteredQueryParams,
{
cached: this.isPoppedState(transition),
cached: this.historyStore.isPoppedState,
}
);

View File

@ -1,4 +1,5 @@
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import $ from "jquery";
import { Promise } from "rsvp";
import { ajax } from "discourse/lib/ajax";
@ -6,6 +7,7 @@ import DiscourseRoute from "discourse/routes/discourse";
import I18n from "discourse-i18n";
export default DiscourseRoute.extend({
historyStore: service(),
templateName: "user/bookmarks",
queryParams: {
@ -13,11 +15,11 @@ export default DiscourseRoute.extend({
q: { refreshModel: true },
},
model(params, transition) {
model(params) {
const controller = this.controllerFor("user-activity-bookmarks");
if (
this.isPoppedState(transition) &&
this.historyStore.isPoppedState &&
this.session.bookmarksModel &&
this.session.bookmarksModel.searchTerm === params.q
) {