(
childThreadInfosMap: {
+[id: string]: $ReadOnlyArray<ResolvedThreadInfo>,
},
communities: $ReadOnlyArray<ResolvedThreadInfo>,
labelStyles: $ReadOnlyArray<LabelStyleType>,
maxDepth: number,
)
| 30 | } |
| 31 | |
| 32 | function 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 | |
| 74 | function threadHasSubchannels( |
| 75 | threadInfo: ResolvedThreadInfo, |
no test coverage detected