FIX: Topic queryParams are removed from history state when scrolling. (#14881)

* Also fixed a bug where the queryParams are not removed when toggling
  between filters.
This commit is contained in:
Alan Guo Xiang Tan 2021-11-11 16:10:00 +08:00 committed by GitHub
parent 729043633e
commit 095255c8ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 3 deletions

View File

@ -103,7 +103,17 @@ export default Controller.extend(bufferedProperty("model"), {
),
updateQueryParams() {
this.setProperties(this.get("model.postStream.streamFilters"));
const filters = this.get("model.postStream.streamFilters");
if (Object.keys(filters).length > 0) {
this.setProperties(filters);
} else {
this.setProperties({
username_filters: null,
filter: null,
replies_to_post_number: null,
});
}
},
@observes("model.title", "category")

View File

@ -183,10 +183,32 @@ const TopicRoute = DiscourseRoute.extend({
}
const topic = this.modelFor("topic");
if (topic && currentPost) {
let postUrl = topic.get("url");
let postUrl;
if (currentPost > 1) {
postUrl += "/" + currentPost;
postUrl = topic.urlForPostNumber(currentPost);
} else {
postUrl = topic.url;
}
if (this._router.currentRoute.queryParams) {
let searchParams;
Object.entries(this._router.currentRoute.queryParams).map(
([key, value]) => {
if (!searchParams) {
searchParams = new URLSearchParams();
}
searchParams.append(key, value);
}
);
if (searchParams) {
postUrl += `?${searchParams.toString()}`;
}
}
cancel(this.scheduledReplace);