This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/controllers/discovery.js
Joffrey JAFFEUX f5eccdd0b8
FIX: ensures period-chooser is not losing query params (#10534)
eg repro before:
- visit http://pr-discourse.test/top/weekly?f=foo
- select another period in the period chooser
- f=foo was gone

After this commit it should still be present
2020-08-26 19:01:08 +02:00

56 lines
1.4 KiB
JavaScript

import { alias, not } from "@ember/object/computed";
import Controller, { inject as controller } from "@ember/controller";
import DiscourseURL from "discourse/lib/url";
import Category from "discourse/models/category";
import { observes } from "discourse-common/utils/decorators";
import { inject as service } from "@ember/service";
export default Controller.extend({
discoveryTopics: controller("discovery/topics"),
navigationCategory: controller("navigation/category"),
application: controller(),
router: service(),
loading: false,
category: alias("navigationCategory.category"),
noSubcategories: alias("navigationCategory.noSubcategories"),
loadedAllItems: not("discoveryTopics.model.canLoadMore"),
@observes("loadedAllItems")
_showFooter: function() {
this.set("application.showFooter", this.loadedAllItems);
},
showMoreUrl(period) {
let url = "",
category = this.category;
if (category) {
url = `/c/${Category.slugFor(category)}/${category.id}${
this.noSubcategories ? "/none" : ""
}/l`;
}
url += "/top/" + period;
const queryParams = this.router.currentRoute.queryParams;
if (Object.keys(queryParams).length) {
url =
`${url}?` +
Object.keys(queryParams)
.map(key => `${key}=${queryParams[key]}`)
.join("&");
}
return url;
},
actions: {
changePeriod(p) {
DiscourseURL.routeTo(this.showMoreUrl(p));
}
}
});