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 { | import { | ||||
type ThreadInfo, | type ThreadInfo, | ||||
type ResolvedThreadInfo, | type ResolvedThreadInfo, | ||||
communitySubthreads, | communitySubthreads, | ||||
} 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) { | ||||
item.itemChildren = itemChildThreadInfos | item.itemChildren = itemChildThreadInfos | ||||
.filter(childItem => communitySubthreads.includes(childItem.type)) | .filter(childItem => communitySubthreads.includes(childItem.type)) | ||||
.map(childItem => ({ | .map(childItem => ({ | ||||
threadInfo: childItem, | threadInfo: childItem, | ||||
itemChildren: [], | itemChildren: [], | ||||
labelStyle: labelStyles[Math.min(lvl + 1, labelStyles.length - 1)], | labelStyle: labelStyles[Math.min(lvl + 1, labelStyles.length - 1)], | ||||
hasSubchannelsButton: | hasSubchannelsButton: | ||||
lvl + 1 === maxDepth && | lvl + 1 === maxDepth && | ||||
threadHasSubchannels(childItem, childThreadInfosMap), | threadHasSubchannels(childItem, childThreadInfosMap), | ||||
inviteLink: inviteLinks?.[item.threadInfo.id], | |||||
inka: can there be links for subchannels? | |||||
tomekAuthorUnsubmitted Done Inline ActionsMaybe in the future we could consider this, but probably not in the near future. Going to make inviteLink undefined for the subchannels. tomek: Maybe in the future we could consider this, but probably not in the near future. Going to make… | |||||
})); | })); | ||||
queue = queue.concat( | queue = queue.concat( | ||||
item.itemChildren.map(childItem => [childItem, lvl + 1]), | item.itemChildren.map(childItem => [childItem, lvl + 1]), | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
Show All 32 Lines |
can there be links for subchannels?