mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 02:25:55 +01:00
fix: #8003, check children recursively
This commit is contained in:
@@ -238,7 +238,7 @@ async function getCategoryData(cids, uid, selectedCid, states) {
|
||||
const cidToWatchState = _.zipObject(cids, watchState);
|
||||
|
||||
const visibleCategories = categoryData.filter(function (c) {
|
||||
const hasVisibleChildren = c && Array.isArray(c.children) && c.children.some(c => c && cidToAllowed[c.cid] && states.includes(cidToWatchState[c.cid]));
|
||||
const hasVisibleChildren = checkVisibleChildren(c, cidToAllowed, cidToWatchState, states);
|
||||
const isCategoryVisible = c && cidToAllowed[c.cid] && !c.link && !c.disabled && states.includes(cidToWatchState[c.cid]);
|
||||
const shouldBeRemoved = !hasVisibleChildren && !isCategoryVisible;
|
||||
|
||||
@@ -281,6 +281,15 @@ async function getCategoryData(cids, uid, selectedCid, states) {
|
||||
};
|
||||
}
|
||||
|
||||
function checkVisibleChildren(c, cidToAllowed, cidToWatchState, states) {
|
||||
if (!c || !Array.isArray(c.children)) {
|
||||
return false;
|
||||
}
|
||||
return c.children.some(c => c && (
|
||||
(cidToAllowed[c.cid] && states.includes(cidToWatchState[c.cid])) || checkVisibleChildren(c, cidToAllowed, cidToWatchState, states)
|
||||
));
|
||||
}
|
||||
|
||||
helpers.getHomePageRoutes = async function (uid) {
|
||||
let cids = await categories.getAllCidsFromSet('categories:cid');
|
||||
cids = await privileges.categories.filterCids('find', cids, uid);
|
||||
|
||||
Reference in New Issue
Block a user