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

66 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-03-13 06:47:23 -07:00
import React, { useMemo } from 'react';
import { PendingItemsRow } from 'soapbox/components/pending-items-row';
import ScrollableList from 'soapbox/components/scrollable-list';
import { useGroup } from 'soapbox/hooks';
import { useGroupMembershipRequests } from 'soapbox/hooks/api/groups/useGroupMembershipRequests';
2023-03-13 06:47:23 -07:00
import { useGroupMembers } from 'soapbox/hooks/api/useGroupMembers';
2023-03-20 05:53:38 -07:00
import { GroupRoles } from 'soapbox/schemas/group-member';
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) => {
const groupId = props.params.id;
2023-03-13 06:47:23 -07:00
const { group, isFetching: isFetchingGroup } = useGroup(groupId);
2023-03-20 05:53:38 -07:00
const { groupMembers: owners, isFetching: isFetchingOwners } = useGroupMembers(groupId, GroupRoles.OWNER);
const { groupMembers: admins, isFetching: isFetchingAdmins } = useGroupMembers(groupId, GroupRoles.ADMIN);
const { groupMembers: users, isFetching: isFetchingUsers, fetchNextPage, hasNextPage } = useGroupMembers(groupId, GroupRoles.USER);
const { accounts: pending, isFetching: isFetchingPending } = useGroupMembershipRequests(groupId);
const isLoading = isFetchingGroup || isFetchingOwners || isFetchingAdmins || isFetchingUsers || isFetchingPending;
2023-03-13 06:47:23 -07:00
const members = useMemo(() => [
2023-03-20 05:53:38 -07:00
...owners,
2023-03-13 06:47:23 -07:00
...admins,
...users,
2023-03-20 05:53:38 -07:00
], [owners, admins, 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'
>
{(pending.length > 0) && (
<PendingItemsRow to={`/groups/${groupId}/manage/requests`} count={pending.length} />
)}
2023-03-13 06:47:23 -07:00
{members.map((member) => (
<GroupMemberListItem
group={group as Group}
member={member}
key={member.account.id}
2023-03-13 06:47:23 -07:00
/>
))}
</ScrollableList>
</>
);
};
export default GroupMembers;