fix: use recursive category lookup for translated filter badge labels

This commit is contained in:
2026-02-07 15:46:58 +01:00
parent affa8bec39
commit 38cc8017ae

View File

@@ -148,13 +148,24 @@ class SearchBox extends HTMLElement {
` `
} }
findCategoryBySlug(tree, slug) {
for (const cat of tree) {
if (cat.slug === slug) return cat
if (cat.children?.length) {
const found = this.findCategoryBySlug(cat.children, slug)
if (found) return found
}
}
return null
}
getCategoryLabel() { getCategoryLabel() {
const cat = this.categoryTree.find(c => c.slug === this.selectedCategory) const cat = this.findCategoryBySlug(this.categoryTree, this.selectedCategory)
if (!cat) return this.selectedCategory if (!cat) return this.selectedCategory
const catName = categoriesService.getTranslatedName(cat) const catName = categoriesService.getTranslatedName(cat)
if (this.selectedSubcategory) { if (this.selectedSubcategory) {
const sub = (cat.children || []).find(s => s.slug === this.selectedSubcategory) const sub = this.findCategoryBySlug(cat.children || [], this.selectedSubcategory)
if (sub) return `${catName} ${categoriesService.getTranslatedName(sub)}` if (sub) return `${catName} ${categoriesService.getTranslatedName(sub)}`
} }
return catName return catName