visible and count
This commit is contained in:
@@ -28,6 +28,7 @@ export class HomeComponent implements OnInit, OnDestroy {
|
||||
topLevelCategories = computed(() => {
|
||||
return this.categories()
|
||||
.filter(cat => cat.parentID === 0)
|
||||
.filter(cat => this.isDisplayableTopLevelCategory(cat))
|
||||
.sort((a, b) => (a.priority ?? Infinity) - (b.priority ?? Infinity));
|
||||
});
|
||||
|
||||
@@ -42,7 +43,7 @@ export class HomeComponent implements OnInit, OnDestroy {
|
||||
private subcategoriesCache = computed(() => {
|
||||
const cache = new Map<number, Category[]>();
|
||||
this.categories().forEach(cat => {
|
||||
if (cat.parentID !== 0) {
|
||||
if (cat.parentID !== 0 && this.isDisplayableFlatSubcategory(cat)) {
|
||||
if (!cache.has(cat.parentID)) {
|
||||
cache.set(cat.parentID, []);
|
||||
}
|
||||
@@ -90,6 +91,21 @@ export class HomeComponent implements OnInit, OnDestroy {
|
||||
return this.subcategoriesCache().get(parentID) || [];
|
||||
}
|
||||
|
||||
private isDisplayableFlatSubcategory(category: Category): boolean {
|
||||
return category.visible !== false
|
||||
&& ((category.itemCount ?? 0) > 0 || (category.subcategories?.length ?? 0) > 0);
|
||||
}
|
||||
|
||||
private isDisplayableTopLevelCategory(category: Category): boolean {
|
||||
return category.visible !== false
|
||||
&& (
|
||||
(category.itemCount ?? 0) > 0
|
||||
|| (category.categoriesCount ?? 0) > 0
|
||||
|| (category.subcategories?.length ?? 0) > 0
|
||||
|| this.getSubCategories(category.categoryID).length > 0
|
||||
);
|
||||
}
|
||||
|
||||
isWideCategory(categoryID: number): boolean {
|
||||
return this.wideCategories().has(categoryID);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user