fix: use recursive category lookup for translated filter badge labels
This commit is contained in:
@@ -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() {
|
||||
const cat = this.categoryTree.find(c => c.slug === this.selectedCategory)
|
||||
const cat = this.findCategoryBySlug(this.categoryTree, this.selectedCategory)
|
||||
if (!cat) return this.selectedCategory
|
||||
|
||||
const catName = categoriesService.getTranslatedName(cat)
|
||||
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)}`
|
||||
}
|
||||
return catName
|
||||
|
||||
Reference in New Issue
Block a user