From ae108b363f97a16f2f8f86ee4dd01b63df6e8f25 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Fri, 25 Oct 2019 10:08:13 +1100 Subject: [PATCH] FIX: Hide muted subcategories (#8239) That bug was mentioned in [meta](https://meta.discourse.org/t/muting-categories-hides-them-muting-subcategories-should-too/131316) Problem is that subcategories are always visible in `/categories` path even if muted. Categories/subcategories are loaded in at least two places https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/models/site.js.es6#L146 https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/routes/discovery-categories.js.es6#L46 I discussed that with @jjaffeux and we thought that maybe it would be a good idea to filter that on frontend level --- .../javascripts/discourse/models/category.js.es6 | 6 ++++++ .../templates/components/categories-only.hbs | 14 ++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/models/category.js.es6 b/app/assets/javascripts/discourse/models/category.js.es6 index 8aa1f1e2c71..ee5101074c7 100644 --- a/app/assets/javascripts/discourse/models/category.js.es6 +++ b/app/assets/javascripts/discourse/models/category.js.es6 @@ -3,6 +3,7 @@ import RestModel from "discourse/models/rest"; import computed from "ember-addons/ember-computed-decorators"; import { on } from "ember-addons/ember-computed-decorators"; import PermissionType from "discourse/models/permission-type"; +import { NotificationLevels } from "discourse/lib/notification-levels"; const Category = RestModel.extend({ permissions: null, @@ -44,6 +45,11 @@ const Category = RestModel.extend({ return { type: "category", id, category: this }; }, + @computed("notification_level") + isMuted(notificationLevel) { + return notificationLevel === NotificationLevels.MUTED; + }, + @computed("name") url() { return Discourse.getURL("/c/") + Category.slugFor(this); diff --git a/app/assets/javascripts/discourse/templates/components/categories-only.hbs b/app/assets/javascripts/discourse/templates/components/categories-only.hbs index 4f93c8a3163..762752097bc 100644 --- a/app/assets/javascripts/discourse/templates/components/categories-only.hbs +++ b/app/assets/javascripts/discourse/templates/components/categories-only.hbs @@ -20,12 +20,14 @@ {{#if c.subcategories}}
- {{#each c.subcategories as |s|}} - - {{category-title-before category=s}} - {{category-link s hideParent="true"}} - {{category-unread category=s}} - + {{#each c.subcategories as |subcategory|}} + {{#unless subcategory.isMuted}} + + {{category-title-before category=subcategory}} + {{category-link subcategory hideParent="true"}} + {{category-unread category=subcategory}} + + {{/unless}} {{/each}}
{{/if}}