Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3375153
D10919.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D10919.diff
View Options
diff --git a/lib/utils/role-utils.js b/lib/utils/role-utils.js
--- a/lib/utils/role-utils.js
+++ b/lib/utils/role-utils.js
@@ -1,8 +1,11 @@
// @flow
+import _groupBy from 'lodash/fp/groupBy.js';
+import _toPairs from 'lodash/fp/toPairs.js';
import * as React from 'react';
import { useSelector } from './redux-utils.js';
+import { useSortedENSResolvedUsers } from '../hooks/ens-cache.js';
import { threadInfoSelector } from '../selectors/thread-selectors.js';
import type {
RelativeMemberInfo,
@@ -93,6 +96,36 @@
return roleMap;
}
+function useMembersGroupedByRole(
+ threadInfo: ThreadInfo,
+): $ReadOnlyMap<string, $ReadOnlyArray<RelativeMemberInfo>> {
+ const { members } = threadInfo;
+ const sortedENSResolvedMembers = useSortedENSResolvedUsers(members);
+
+ const roles = useRolesFromCommunityThreadInfo(
+ threadInfo,
+ sortedENSResolvedMembers,
+ );
+
+ const groupByRoleName = React.useMemo(
+ () =>
+ _groupBy(member => roles.get(member.id)?.name)(sortedENSResolvedMembers),
+ [sortedENSResolvedMembers, roles],
+ );
+
+ const membersGroupedByRoleMap = React.useMemo(() => {
+ const map: Map<string, $ReadOnlyArray<RelativeMemberInfo>> = new Map();
+
+ _toPairs(groupByRoleName)
+ .sort((a, b) => a[0].localeCompare(b[0]))
+ .forEach(([roleName, memberInfos]) => map.set(roleName, memberInfos));
+
+ return map;
+ }, [groupByRoleName]);
+
+ return membersGroupedByRoleMap;
+}
+
function toggleUserSurfacedPermission(
rolePermissions: ThreadRolePermissionsBlob,
userSurfacedPermission: UserSurfacedPermission,
@@ -124,4 +157,5 @@
useRoleDeletableAndEditableStatus,
useRolesFromCommunityThreadInfo,
toggleUserSurfacedPermission,
+ useMembersGroupedByRole,
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 6:37 PM (22 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2591352
Default Alt Text
D10919.diff (1 KB)
Attached To
Mode
D10919: [lib] introduce useMembersGroupedByRole
Attached
Detach File
Event Timeline
Log In to Comment