Refactor 'usePendingGroups' into new api hooks

This commit is contained in:
Chewbacca
2023-06-28 14:50:46 -04:00
parent 11f100da51
commit 6f2e0749b6
6 changed files with 40 additions and 61 deletions

View File

@ -0,0 +1,30 @@
import { Entities } from 'soapbox/entity-store/entities';
import { useEntities } from 'soapbox/entity-store/hooks';
import { useApi, useFeatures, useOwnAccount } from 'soapbox/hooks';
import { Group, groupSchema } from 'soapbox/schemas';
function usePendingGroups() {
const api = useApi();
const { account } = useOwnAccount();
const features = useFeatures();
const { entities, ...result } = useEntities<Group>(
[Entities.GROUPS, account?.id as string, 'pending'],
() => api.get('/api/v1/groups', {
params: {
pending: true,
},
}),
{
schema: groupSchema,
enabled: !!account && features.groupsPending,
},
);
return {
...result,
groups: entities,
};
}
export { usePendingGroups };

View File

@ -35,6 +35,7 @@ export { useGroupsFromTag } from './groups/useGroupsFromTag';
export { useJoinGroup } from './groups/useJoinGroup';
export { useMuteGroup } from './groups/useMuteGroup';
export { useLeaveGroup } from './groups/useLeaveGroup';
export { usePendingGroups } from './groups/usePendingGroups';
export { usePopularGroups } from './groups/usePopularGroups';
export { usePopularTags } from './groups/usePopularTags';
export { usePromoteGroupMember } from './groups/usePromoteGroupMember';