fix human language category selection when duplicates exist
Prefer the most populated Human Language category (then latest id fallback) so sub-categories and courses render correctly when multiple same-name categories are present. Made-with: Cursor
This commit is contained in:
parent
5206fb2e1a
commit
da6754e6f5
|
|
@ -574,9 +574,21 @@ export const getHumanLanguageHierarchy = () =>
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const selectedCategory =
|
const categories = Array.from(categoryMap.values())
|
||||||
Array.from(categoryMap.values()).find((c) => c.category_name.toLowerCase().includes("human")) ??
|
const humanLanguageCandidates = categories.filter((c) => c.category_name.toLowerCase().includes("human"))
|
||||||
Array.from(categoryMap.values())[0]
|
|
||||||
|
const selectedCategory = (humanLanguageCandidates.length ? humanLanguageCandidates : categories).sort((a, b) => {
|
||||||
|
const aSubCategoryCount = a.sub_categories.size
|
||||||
|
const bSubCategoryCount = b.sub_categories.size
|
||||||
|
if (aSubCategoryCount !== bSubCategoryCount) return bSubCategoryCount - aSubCategoryCount
|
||||||
|
|
||||||
|
const aCourseCount = Array.from(a.sub_categories.values()).reduce((sum, sub) => sum + sub.courses.size, 0)
|
||||||
|
const bCourseCount = Array.from(b.sub_categories.values()).reduce((sum, sub) => sum + sub.courses.size, 0)
|
||||||
|
if (aCourseCount !== bCourseCount) return bCourseCount - aCourseCount
|
||||||
|
|
||||||
|
// If tied on richness, pick the latest category id.
|
||||||
|
return b.category_id - a.category_id
|
||||||
|
})[0]
|
||||||
|
|
||||||
if (!selectedCategory) {
|
if (!selectedCategory) {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user