EntityStore: switch all hooks to use a callback function
This commit is contained in:
@@ -11,20 +11,20 @@ function useGroupMembershipRequests(groupId: string) {
|
||||
|
||||
const { entities, invalidate, ...rest } = useEntities(
|
||||
path,
|
||||
`/api/v1/groups/${groupId}/membership_requests`,
|
||||
() => api.get(`/api/v1/groups/${groupId}/membership_requests`),
|
||||
{ schema: accountSchema },
|
||||
);
|
||||
|
||||
const authorize = useIncrementEntity(path, -1, (accountId: string) => {
|
||||
return api
|
||||
.post(`/api/v1/groups/${groupId}/membership_requests/${accountId}/authorize`)
|
||||
.then(invalidate);
|
||||
const { incrementEntity: authorize } = useIncrementEntity(path, -1, async (accountId: string) => {
|
||||
const response = await api.post(`/api/v1/groups/${groupId}/membership_requests/${accountId}/authorize`);
|
||||
invalidate();
|
||||
return response;
|
||||
});
|
||||
|
||||
const reject = useIncrementEntity(path, -1, (accountId: string) => {
|
||||
return api
|
||||
.post(`/api/v1/groups/${groupId}/membership_requests/${accountId}/reject`)
|
||||
.then(invalidate);
|
||||
const { incrementEntity: reject } = useIncrementEntity(path, -1, async (accountId: string) => {
|
||||
const response = await api.post(`/api/v1/groups/${groupId}/membership_requests/${accountId}/reject`);
|
||||
invalidate();
|
||||
return response;
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -2,10 +2,14 @@ import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntities } from 'soapbox/entity-store/hooks';
|
||||
import { GroupMember, groupMemberSchema } from 'soapbox/schemas';
|
||||
|
||||
import { useApi } from '../useApi';
|
||||
|
||||
function useGroupMembers(groupId: string, role: string) {
|
||||
const api = useApi();
|
||||
|
||||
const { entities, ...result } = useEntities<GroupMember>(
|
||||
[Entities.GROUP_MEMBERSHIPS, groupId, role],
|
||||
`/api/v1/groups/${groupId}/memberships?role=${role}`,
|
||||
() => api.get(`/api/v1/groups/${groupId}/memberships?role=${role}`),
|
||||
{ schema: groupMemberSchema },
|
||||
);
|
||||
|
||||
|
||||
@@ -2,15 +2,17 @@ import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntities } from 'soapbox/entity-store/hooks';
|
||||
import { Group, groupSchema } from 'soapbox/schemas';
|
||||
|
||||
import { useApi } from '../useApi';
|
||||
import { useFeatures } from '../useFeatures';
|
||||
import { useGroupRelationships } from '../useGroups';
|
||||
|
||||
function usePopularGroups() {
|
||||
const api = useApi();
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<Group>(
|
||||
[Entities.GROUPS, 'popular'],
|
||||
'/api/mock/groups', // '/api/v1/truth/trends/groups'
|
||||
() => api.get('/api/mock/groups'), // '/api/v1/truth/trends/groups'
|
||||
{
|
||||
schema: groupSchema,
|
||||
enabled: features.groupsDiscovery,
|
||||
|
||||
@@ -2,15 +2,17 @@ import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntities } from 'soapbox/entity-store/hooks';
|
||||
import { Group, groupSchema } from 'soapbox/schemas';
|
||||
|
||||
import { useApi } from '../useApi';
|
||||
import { useFeatures } from '../useFeatures';
|
||||
import { useGroupRelationships } from '../useGroups';
|
||||
|
||||
function useSuggestedGroups() {
|
||||
const api = useApi();
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<Group>(
|
||||
[Entities.GROUPS, 'suggested'],
|
||||
'/api/mock/groups', // '/api/v1/truth/suggestions/groups'
|
||||
() => api.get('/api/mock/groups'), // '/api/v1/truth/suggestions/groups'
|
||||
{
|
||||
schema: groupSchema,
|
||||
enabled: features.groupsDiscovery,
|
||||
|
||||
Reference in New Issue
Block a user