FIX: Hide muted categories from hamburger menu top categories block
This commit is contained in:
commit
176d8ca78d
|
@ -184,6 +184,8 @@ export default createWidget("hamburger-menu", {
|
||||||
if (this.currentUser) {
|
if (this.currentUser) {
|
||||||
let categoryIds = this.currentUser.get("top_category_ids") || [];
|
let categoryIds = this.currentUser.get("top_category_ids") || [];
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
const mutedCategoryIds = this.currentUser.get("muted_category_ids") || [];
|
||||||
|
categories = categories.filter(c => !mutedCategoryIds.includes(c.id));
|
||||||
categoryIds.forEach(id => {
|
categoryIds.forEach(id => {
|
||||||
const category = categories.find(c => c.id === id);
|
const category = categories.find(c => c.id === id);
|
||||||
if (category) {
|
if (category) {
|
||||||
|
|
|
@ -3,6 +3,8 @@ import { moduleForWidget, widgetTest } from "helpers/widget-test";
|
||||||
moduleForWidget("hamburger-menu");
|
moduleForWidget("hamburger-menu");
|
||||||
|
|
||||||
const topCategoryIds = [2, 3, 1];
|
const topCategoryIds = [2, 3, 1];
|
||||||
|
let mutedCategoryIds = [];
|
||||||
|
let categoriesByCount = [];
|
||||||
|
|
||||||
widgetTest("prioritize faq", {
|
widgetTest("prioritize faq", {
|
||||||
template: '{{mount-widget widget="hamburger-menu"}}',
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
||||||
|
@ -136,10 +138,11 @@ widgetTest("top categories - anonymous", {
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
this.siteSettings.hamburger_menu_categories_count = 8;
|
this.siteSettings.hamburger_menu_categories_count = 8;
|
||||||
maxCategoriesToDisplay = this.siteSettings.hamburger_menu_categories_count;
|
maxCategoriesToDisplay = this.siteSettings.hamburger_menu_categories_count;
|
||||||
|
categoriesByCount = this.site.get("categoriesByCount");
|
||||||
},
|
},
|
||||||
|
|
||||||
test(assert) {
|
test(assert) {
|
||||||
const count = this.site.get("categoriesByCount").length;
|
const count = categoriesByCount.length;
|
||||||
const maximum =
|
const maximum =
|
||||||
count <= maxCategoriesToDisplay ? count : maxCategoriesToDisplay;
|
count <= maxCategoriesToDisplay ? count : maxCategoriesToDisplay;
|
||||||
assert.equal(find(".category-link").length, maximum);
|
assert.equal(find(".category-link").length, maximum);
|
||||||
|
@ -152,21 +155,32 @@ widgetTest("top categories", {
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
this.siteSettings.hamburger_menu_categories_count = 8;
|
this.siteSettings.hamburger_menu_categories_count = 8;
|
||||||
maxCategoriesToDisplay = this.siteSettings.hamburger_menu_categories_count;
|
maxCategoriesToDisplay = this.siteSettings.hamburger_menu_categories_count;
|
||||||
|
categoriesByCount = this.site.get("categoriesByCount");
|
||||||
|
categoriesByCount.every(c => {
|
||||||
|
if (!topCategoryIds.includes(c.id)) {
|
||||||
|
mutedCategoryIds.push(c.id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
this.currentUser.set("top_category_ids", topCategoryIds);
|
this.currentUser.set("top_category_ids", topCategoryIds);
|
||||||
|
this.currentUser.set("muted_category_ids", mutedCategoryIds);
|
||||||
},
|
},
|
||||||
|
|
||||||
test(assert) {
|
test(assert) {
|
||||||
assert.equal(find(".category-link").length, maxCategoriesToDisplay);
|
assert.equal(find(".category-link").length, maxCategoriesToDisplay);
|
||||||
|
|
||||||
const categoriesList = this.site.get("categoriesByCount");
|
categoriesByCount = categoriesByCount.filter(
|
||||||
|
c => !mutedCategoryIds.includes(c.id)
|
||||||
|
);
|
||||||
let ids = topCategoryIds
|
let ids = topCategoryIds
|
||||||
.concat(categoriesList.map(c => c.id))
|
.concat(categoriesByCount.map(c => c.id))
|
||||||
.uniq()
|
.uniq()
|
||||||
.slice(0, maxCategoriesToDisplay);
|
.slice(0, maxCategoriesToDisplay);
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
find(".category-link .category-name").text(),
|
find(".category-link .category-name").text(),
|
||||||
ids.map(i => categoriesList.find(c => c.id === i).name).join("")
|
ids.map(i => categoriesByCount.find(c => c.id === i).name).join("")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue