bigbuffet-rw/app/soapbox/hooks/api/useGroupMembers.ts

22 lines
615 B
TypeScript
Raw Normal View History

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
import { useApi } from '../useApi';
2023-03-13 06:47:23 -07:00
function useGroupMembers(groupId: string, role: string) {
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],
() => 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 };