diff --git a/src/app/features/add-existing/AddExisting.tsx b/src/app/features/add-existing/AddExisting.tsx index a934e7908..03bb32a87 100644 --- a/src/app/features/add-existing/AddExisting.tsx +++ b/src/app/features/add-existing/AddExisting.tsx @@ -107,13 +107,7 @@ export function AddExistingModal({ parentId, space, requestClose }: AddExistingM return true; } - let hasAncestor = false; - parentIds.forEach((id) => { - if (isAncestor(sourceId, id, visited)) { - hasAncestor = true; - } - }); - return hasAncestor; + return Array.from(parentIds).some((id) => isAncestor(sourceId, id, visited)); }, [roomIdToParents] ); diff --git a/src/app/features/lobby/Lobby.tsx b/src/app/features/lobby/Lobby.tsx index 6c4bda637..d51854d4b 100644 --- a/src/app/features/lobby/Lobby.tsx +++ b/src/app/features/lobby/Lobby.tsx @@ -235,14 +235,9 @@ export function Lobby() { // As a subspace can be in multiple spaces, // only return true if all parent spaces are closed. - let anyOpen = false; - parentParentIds.forEach((id) => { - if (!getInClosedCategories(spaceId, id, parentId)) { - anyOpen = true; - } - }); - closedCategoriesCache.current.set(categoryId, !anyOpen); - return !anyOpen; + return !Array.from(parentParentIds).some( + (id) => !getInClosedCategories(spaceId, id, parentId) + ); }, [closedCategories, getRoom, roomToParents, spaceRooms] ); @@ -261,13 +256,7 @@ export function Lobby() { return false; } - let allCollapsed = true; - parentIds.forEach((id) => { - if (!getInClosedCategories(spaceId, id, roomId)) { - allCollapsed = false; - } - }); - return allCollapsed; + return !Array.from(parentIds).some((id) => !getInClosedCategories(spaceId, id, roomId)); }; const [draggingItem, setDraggingItem] = useState(); diff --git a/src/app/pages/client/space/Space.tsx b/src/app/pages/client/space/Space.tsx index 104457e79..42565ab14 100644 --- a/src/app/pages/client/space/Space.tsx +++ b/src/app/pages/client/space/Space.tsx @@ -453,14 +453,11 @@ export function Space() { // As a subspace can be in multiple spaces, // only return true if all parent spaces are closed. - let anyOpen = false; - parentParentIds.forEach((id) => { - if (!getInClosedCategories(spaceId, id, parentId)) { - anyOpen = true; - } - }); - closedCategoriesCache.current.set(categoryId, !anyOpen); - return !anyOpen; + const allClosed = !Array.from(parentParentIds).some( + (id) => !getInClosedCategories(spaceId, id, parentId) + ); + closedCategoriesCache.current.set(categoryId, allClosed); + return allClosed; }, [closedCategories, getRoom, roomToParents, spaceRooms] ); @@ -482,14 +479,7 @@ export function Space() { return false; } - let visible = false; - childIds.forEach((id) => { - if (getContainsShowRoom(id)) { - visible = true; - } - }); - - return visible; + return Array.from(childIds).some((id) => getContainsShowRoom(id)); }, [roomToUnread, selectedRoomId, roomToChildren] ); @@ -513,13 +503,9 @@ export function Space() { return false; } - let allCollapsed = true; - parentIds.forEach((id) => { - if (!getInClosedCategories(spaceId, id, roomId)) { - allCollapsed = false; - } - }); - + const allCollapsed = !Array.from(parentIds).some( + (id) => !getInClosedCategories(spaceId, id, roomId) + ); ancestorsCollapsedCache.current.set(categoryId, allCollapsed); return allCollapsed; };