MCPcopy Create free account
hub / github.com/CommE2E/comm / createRecursiveDrawerItemsData

Function createRecursiveDrawerItemsData

lib/utils/drawer-utils.react.js:32–72  ·  view source on GitHub ↗
(
  childThreadInfosMap: {
    +[id: string]: $ReadOnlyArray<ResolvedThreadInfo>,
  },
  communities: $ReadOnlyArray<ResolvedThreadInfo>,
  labelStyles: $ReadOnlyArray<LabelStyleType>,
  maxDepth: number,
)

Source from the content-addressed store, hash-verified

30}
31
32function createRecursiveDrawerItemsData<LabelStyleType>(
33 childThreadInfosMap: {
34 +[id: string]: $ReadOnlyArray<ResolvedThreadInfo>,
35 },
36 communities: $ReadOnlyArray<ResolvedThreadInfo>,
37 labelStyles: $ReadOnlyArray<LabelStyleType>,
38 maxDepth: number,
39): $ReadOnlyArray<CommunityDrawerItemData<LabelStyleType>> {
40 const result: Array<WritableCommunityDrawerItemData<LabelStyleType>> =
41 communities.map(community => ({
42 threadInfo: community,
43 itemChildren: [],
44 labelStyle: labelStyles[0],
45 hasSubchannelsButton: false,
46 }));
47 result.sort(compareCommunityDrawerItemData);
48 let queue = result.map(item => [item, 0]);
49
50 for (let i = 0; i < queue.length; i++) {
51 const [item, lvl] = queue[i];
52 const itemChildThreadInfos = childThreadInfosMap[item.threadInfo.id] ?? [];
53
54 if (lvl < maxDepth) {
55 item.itemChildren = itemChildThreadInfos
56 .filter(childItem => communitySubthreads.includes(childItem.type))
57 .map(childItem => ({
58 threadInfo: childItem,
59 itemChildren: [],
60 labelStyle: labelStyles[Math.min(lvl + 1, labelStyles.length - 1)],
61 hasSubchannelsButton:
62 lvl + 1 === maxDepth &&
63 threadHasSubchannels(childItem, childThreadInfosMap),
64 }));
65 item.itemChildren.sort(compareCommunityDrawerItemData);
66 queue = queue.concat(
67 item.itemChildren.map(childItem => [childItem, lvl + 1]),
68 );
69 }
70 }
71 return result;
72}
73
74function threadHasSubchannels(
75 threadInfo: ResolvedThreadInfo,

Callers 2

CommunityDrawerContentFunction · 0.90

Calls 1

threadHasSubchannelsFunction · 0.85

Tested by

no test coverage detected