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/components/d-navigation.js.es6
Joffrey JAFFEUX a5542768ea
FIX: attempts to use params from addDiscoveryQueryParam (#8007)
This commit will for example allow this:

```
api.addDiscoveryQueryParam("my_param", { persist: true });
```

If you page is forum.foo.bar/?my_param=1, when clicking on an "unread" link for example this query string will be kept.
2019-08-14 19:56:02 +02:00

55 lines
1.5 KiB
JavaScript

import computed from "ember-addons/ember-computed-decorators";
export default Ember.Component.extend({
router: Ember.inject.service(),
persistedQueryParams: null,
tagName: "",
@computed("category")
showCategoryNotifications(category) {
return category && this.currentUser;
},
@computed()
categories() {
return this.site.get("categoriesList");
},
@computed("hasDraft")
createTopicLabel(hasDraft) {
return hasDraft ? "topic.open_draft" : "topic.create";
},
@computed("category.can_edit")
showCategoryEdit: canEdit => canEdit,
@computed("filterMode", "category", "noSubcategories")
navItems(filterMode, category, noSubcategories) {
// we don't want to show the period in the navigation bar since it's in a dropdown
if (filterMode.indexOf("top/") === 0) {
filterMode = filterMode.replace("top/", "");
}
let params;
const currentRouteQueryParams = this.get("router.currentRoute.queryParams");
if (this.persistedQueryParams && currentRouteQueryParams) {
const currentKeys = Object.keys(currentRouteQueryParams);
const discoveryKeys = Object.keys(this.persistedQueryParams);
const supportedKeys = currentKeys.filter(
i => discoveryKeys.indexOf(i) > 0
);
params = supportedKeys.reduce((object, key) => {
object[key] = currentRouteQueryParams[key];
return object;
}, {});
}
return Discourse.NavItem.buildList(category, {
filterMode,
noSubcategories,
persistedQueryParams: params
});
}
});