2023-03-13 06:47:23 -07:00
|
|
|
import { Entities } from 'soapbox/entity-store/entities';
|
|
|
|
import { useEntities } from 'soapbox/entity-store/hooks';
|
2023-03-13 12:08:02 -07:00
|
|
|
import { GroupMember, groupMemberSchema } from 'soapbox/schemas';
|
2023-03-13 06:47:23 -07:00
|
|
|
|
2023-03-23 17:22:26 -07:00
|
|
|
import { useApi } from '../useApi';
|
|
|
|
|
2023-03-13 06:47:23 -07:00
|
|
|
function useGroupMembers(groupId: string, role: string) {
|
2023-03-23 17:22:26 -07:00
|
|
|
const api = useApi();
|
|
|
|
|
2023-03-13 06:47:23 -07:00
|
|
|
const { entities, ...result } = useEntities<GroupMember>(
|
2023-03-13 12:08:02 -07:00
|
|
|
[Entities.GROUP_MEMBERSHIPS, groupId, role],
|
2023-03-23 17:22:26 -07:00
|
|
|
() => api.get(`/api/v1/groups/${groupId}/memberships?role=${role}`),
|
2023-03-14 09:55:42 -07:00
|
|
|
{ schema: groupMemberSchema },
|
2023-03-13 06:47:23 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...result,
|
|
|
|
groupMembers: entities,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export { useGroupMembers };
|