fixes
This commit is contained in:
40
index.html
40
index.html
@@ -705,6 +705,21 @@
|
|||||||
container.appendChild(ul);
|
container.appendChild(ul);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function countSubcategoryArticles(children) {
|
||||||
|
let total = 0;
|
||||||
|
children.forEach(child => {
|
||||||
|
// Count articles in this child
|
||||||
|
const childCount = child.products ? child.products.length : child.articleCount;
|
||||||
|
total += childCount;
|
||||||
|
|
||||||
|
// Recursively count articles in nested subcategories
|
||||||
|
if (child.children && child.children.length > 0) {
|
||||||
|
total += countSubcategoryArticles(child.children);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
function renderCategory(category) {
|
function renderCategory(category) {
|
||||||
// category might be a filtered copy or original.
|
// category might be a filtered copy or original.
|
||||||
// If it's a copy, it has _original pointing to the real state node.
|
// If it's a copy, it has _original pointing to the real state node.
|
||||||
@@ -764,19 +779,30 @@
|
|||||||
|
|
||||||
const count = document.createElement('div');
|
const count = document.createElement('div');
|
||||||
count.className = 'category-count';
|
count.className = 'category-count';
|
||||||
// Use original counts or filtered counts?
|
// When filtering, show actual matching product count
|
||||||
// "remove all articles ... with no match"
|
// If this category is not a direct match (only matches due to subcategories),
|
||||||
// If filtered, we should probably show the count of MATCHING articles?
|
// and products aren't loaded, show 0 instead of total articleCount
|
||||||
// User didn't specify, but it makes sense to show matching count if filtered.
|
let productCount;
|
||||||
// But articleCount comes from API.
|
if (category.products !== null && category.products !== undefined) {
|
||||||
// We can calculate it from products array if loaded.
|
// Products are loaded, use the filtered count
|
||||||
const productCount = category.products ? category.products.length : category.articleCount;
|
productCount = category.products.length;
|
||||||
|
} else if (state.filter && !realNode._isDirectMatch) {
|
||||||
|
// Filtering is active and this is not a direct match, so show 0
|
||||||
|
productCount = 0;
|
||||||
|
} else {
|
||||||
|
// No filter or is a direct match, use API count
|
||||||
|
productCount = category.articleCount;
|
||||||
|
}
|
||||||
let countText = `${productCount} articles`;
|
let countText = `${productCount} articles`;
|
||||||
|
|
||||||
// Always show subcategory count if children exist (User requirement)
|
// Always show subcategory count if children exist (User requirement)
|
||||||
// Use filtered children length
|
// Use filtered children length
|
||||||
if (category.children && category.children.length > 0) {
|
if (category.children && category.children.length > 0) {
|
||||||
|
const subcategoryArticleCount = countSubcategoryArticles(category.children);
|
||||||
countText += `, ${category.children.length} subcategories`;
|
countText += `, ${category.children.length} subcategories`;
|
||||||
|
if (subcategoryArticleCount > 0) {
|
||||||
|
countText += ` with ${subcategoryArticleCount} more articles`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
count.textContent = countText;
|
count.textContent = countText;
|
||||||
info.appendChild(count);
|
info.appendChild(count);
|
||||||
|
|||||||
Reference in New Issue
Block a user