Changeset View
Changeset View
Standalone View
Standalone View
lib/utils/drawer-utils.react.js
// @flow | // @flow | ||||
import { threadIsChannel } from '../shared/thread-utils.js'; | import { threadIsChannel } from '../shared/thread-utils.js'; | ||||
import type { InviteLink } from '../types/link-types.js'; | |||||
import { communitySubthreads } from '../types/thread-types-enum.js'; | import { communitySubthreads } from '../types/thread-types-enum.js'; | ||||
import { | import { | ||||
type ThreadInfo, | type ThreadInfo, | ||||
type ResolvedThreadInfo, | type ResolvedThreadInfo, | ||||
} from '../types/thread-types.js'; | } from '../types/thread-types.js'; | ||||
export type CommunityDrawerItemData<T> = { | export type CommunityDrawerItemData<T> = { | ||||
+threadInfo: ThreadInfo, | +threadInfo: ThreadInfo, | ||||
+itemChildren?: $ReadOnlyArray<CommunityDrawerItemData<T>>, | +itemChildren?: $ReadOnlyArray<CommunityDrawerItemData<T>>, | ||||
+hasSubchannelsButton: boolean, | +hasSubchannelsButton: boolean, | ||||
+labelStyle: T, | +labelStyle: T, | ||||
+inviteLink?: ?InviteLink, | |||||
}; | }; | ||||
function createRecursiveDrawerItemsData<LabelStyleType>( | function createRecursiveDrawerItemsData<LabelStyleType>( | ||||
childThreadInfosMap: { +[id: string]: $ReadOnlyArray<ThreadInfo> }, | childThreadInfosMap: { +[id: string]: $ReadOnlyArray<ThreadInfo> }, | ||||
communities: $ReadOnlyArray<ResolvedThreadInfo>, | communities: $ReadOnlyArray<ResolvedThreadInfo>, | ||||
labelStyles: $ReadOnlyArray<LabelStyleType>, | labelStyles: $ReadOnlyArray<LabelStyleType>, | ||||
maxDepth: number, | maxDepth: number, | ||||
inviteLinks: ?{ +[threadID: string]: InviteLink }, | |||||
): $ReadOnlyArray<CommunityDrawerItemData<LabelStyleType>> { | ): $ReadOnlyArray<CommunityDrawerItemData<LabelStyleType>> { | ||||
const result = communities.map(community => ({ | const result = communities.map(community => ({ | ||||
threadInfo: community, | threadInfo: community, | ||||
itemChildren: [], | itemChildren: [], | ||||
labelStyle: labelStyles[0], | labelStyle: labelStyles[0], | ||||
hasSubchannelsButton: false, | hasSubchannelsButton: false, | ||||
inviteLink: inviteLinks?.[community.id], | |||||
})); | })); | ||||
let queue = result.map(item => [item, 0]); | let queue = result.map(item => [item, 0]); | ||||
for (let i = 0; i < queue.length; i++) { | for (let i = 0; i < queue.length; i++) { | ||||
const [item, lvl] = queue[i]; | const [item, lvl] = queue[i]; | ||||
const itemChildThreadInfos = childThreadInfosMap[item.threadInfo.id] ?? []; | const itemChildThreadInfos = childThreadInfosMap[item.threadInfo.id] ?? []; | ||||
if (lvl < maxDepth) { | if (lvl < maxDepth) { | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |