pleroma/app/soapbox/features/group/group-members.tsx

62 lines
2 KiB
TypeScript
Raw Normal View History

2023-03-13 06:47:23 -07:00
import React, { useMemo } from 'react';
import ScrollableList from 'soapbox/components/scrollable-list';
2023-03-13 06:47:23 -07:00
import { useGroupMembers } from 'soapbox/hooks/api/useGroupMembers';
import { useGroupRoles } from 'soapbox/hooks/useGroupRoles';
import { useGroup } from 'soapbox/queries/groups';
import PlaceholderAccount from '../placeholder/components/placeholder-account';
2023-03-13 06:47:23 -07:00
import GroupMemberListItem from './components/group-member-list-item';
2023-03-13 06:47:23 -07:00
import type { Group } from 'soapbox/types/entities';
interface IGroupMembers {
2023-03-13 06:47:23 -07:00
params: { id: string }
}
const GroupMembers: React.FC<IGroupMembers> = (props) => {
2023-03-13 06:47:23 -07:00
const { roles: { admin, moderator, user } } = useGroupRoles();
const groupId = props.params.id;
2023-03-13 06:47:23 -07:00
const { group, isFetching: isFetchingGroup } = useGroup(groupId);
const { groupMembers: admins, isFetching: isFetchingAdmins } = useGroupMembers(groupId, admin);
const { groupMembers: moderators, isFetching: isFetchingModerators } = useGroupMembers(groupId, moderator);
const { groupMembers: users, isFetching: isFetchingUsers, fetchNextPage, hasNextPage } = useGroupMembers(groupId, user);
2023-03-13 06:47:23 -07:00
const isLoading = isFetchingGroup || isFetchingAdmins || isFetchingModerators || isFetchingUsers;
2023-03-13 06:47:23 -07:00
const members = useMemo(() => [
...admins,
...moderators,
...users,
], [admins, moderators, users]);
return (
<>
2023-03-13 06:47:23 -07:00
<ScrollableList
scrollKey='group-members'
hasMore={hasNextPage}
onLoadMore={fetchNextPage}
isLoading={isLoading || !group}
showLoading={!group || isLoading && members.length === 0}
placeholderComponent={PlaceholderAccount}
placeholderCount={3}
className='divide-y divide-solid divide-gray-300'
itemClassName='py-3 last:pb-0'
>
{members.map((member) => (
<GroupMemberListItem
group={group as Group}
member={member}
key={member?.account}
/>
))}
</ScrollableList>
</>
);
};
export default GroupMembers;