diff --git a/lib/utils/drawer-utils.react.js b/lib/utils/drawer-utils.react.js --- a/lib/utils/drawer-utils.react.js +++ b/lib/utils/drawer-utils.react.js @@ -13,13 +13,21 @@ type WritableCommunityDrawerItemData = { threadInfo: ResolvedThreadInfo, - itemChildren: $ReadOnlyArray>, + itemChildren: Array>, hasSubchannelsButton: boolean, labelStyle: T, }; -export type CommunityDrawerItemData = $ReadOnly< - WritableCommunityDrawerItemData, ->; +export type CommunityDrawerItemData = $ReadOnly<{ + ...WritableCommunityDrawerItemData, + +itemChildren: $ReadOnlyArray>, +}>; + +function compareCommunityDrawerItemData( + a: CommunityDrawerItemData, + b: CommunityDrawerItemData, +): number { + return a.threadInfo.uiName.localeCompare(b.threadInfo.uiName); +} function createRecursiveDrawerItemsData( childThreadInfosMap: { @@ -29,14 +37,14 @@ labelStyles: $ReadOnlyArray, maxDepth: number, ): $ReadOnlyArray> { - const result: $ReadOnlyArray< - WritableCommunityDrawerItemData, - > = communities.map(community => ({ - threadInfo: community, - itemChildren: [], - labelStyle: labelStyles[0], - hasSubchannelsButton: false, - })); + const result: Array> = + communities.map(community => ({ + threadInfo: community, + itemChildren: [], + labelStyle: labelStyles[0], + hasSubchannelsButton: false, + })); + result.sort(compareCommunityDrawerItemData); let queue = result.map(item => [item, 0]); for (let i = 0; i < queue.length; i++) { @@ -54,6 +62,7 @@ lvl + 1 === maxDepth && threadHasSubchannels(childItem, childThreadInfosMap), })); + item.itemChildren.sort(compareCommunityDrawerItemData); queue = queue.concat( item.itemChildren.map(childItem => [childItem, lvl + 1]), );