Page MenuHomePhabricator

D8105.id27697.diff
No OneTemporary

D8105.id27697.diff

diff --git a/native/utils/drawer-utils.react.js b/native/utils/drawer-utils.react.js
--- a/native/utils/drawer-utils.react.js
+++ b/native/utils/drawer-utils.react.js
@@ -72,4 +72,47 @@
return results;
}
-export { flattenDrawerItemsData };
+function findAllDescendantIDs<T>(
+ data: $ReadOnlyArray<CommunityDrawerItemData<T>>,
+): $ReadOnlyArray<string> {
+ const results = [];
+ for (const item of data) {
+ results.push(item.threadInfo.id);
+ results.concat(findAllDescendantIDs(item.itemChildren));
+ }
+ return results;
+}
+
+function findThreadChildrenItems<T>(
+ data: $ReadOnlyArray<CommunityDrawerItemData<T>>,
+ id: string,
+): ?$ReadOnlyArray<CommunityDrawerItemData<T>> {
+ for (const item of data) {
+ if (item.threadInfo.id === id) {
+ return item.itemChildren;
+ }
+ const result = findThreadChildrenItems(item.itemChildren, id);
+ if (result) {
+ return result;
+ }
+ }
+ return undefined;
+}
+
+function filterOutThreadAndDescendantIDs<T>(
+ idsToFilter: $ReadOnlyArray<string>,
+ allItems: $ReadOnlyArray<CommunityDrawerItemData<T>>,
+ threadID: string,
+): $ReadOnlyArray<string> {
+ const childItems = findThreadChildrenItems(allItems, threadID);
+ if (!childItems) {
+ return [];
+ }
+ const descendants = findAllDescendantIDs(childItems);
+ const descendantsSet = new Set(descendants);
+ return idsToFilter.filter(
+ item => !descendantsSet.has(item) && item !== threadID,
+ );
+}
+
+export { flattenDrawerItemsData, filterOutThreadAndDescendantIDs };

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 24, 7:07 PM (8 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2699898
Default Alt Text
D8105.id27697.diff (1 KB)

Event Timeline