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
2019-10-29 13:31:44 -04:00

57 lines
1.6 KiB
JavaScript

import { inject as service } from "@ember/service";
import Component from "@ember/component";
import computed from "ember-addons/ember-computed-decorators";
export default Component.extend({
router: 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
});
}
});