isLoading --> isSubmitting for action hooks
This commit is contained in:
parent
c9a724525e
commit
a4992eec4d
7 changed files with 16 additions and 16 deletions
|
@ -15,7 +15,7 @@ function useDeleteEntity(
|
||||||
) {
|
) {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const getState = useGetState();
|
const getState = useGetState();
|
||||||
const [isLoading, setPromise] = useLoading();
|
const [isSubmitting, setPromise] = useLoading();
|
||||||
|
|
||||||
async function deleteEntity(entityId: string, callbacks: EntityCallbacks<string> = {}): Promise<void> {
|
async function deleteEntity(entityId: string, callbacks: EntityCallbacks<string> = {}): Promise<void> {
|
||||||
// Get the entity before deleting, so we can reverse the action if the API request fails.
|
// Get the entity before deleting, so we can reverse the action if the API request fails.
|
||||||
|
@ -47,7 +47,7 @@ function useDeleteEntity(
|
||||||
|
|
||||||
return {
|
return {
|
||||||
deleteEntity,
|
deleteEntity,
|
||||||
isLoading,
|
isSubmitting,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,16 +24,16 @@ function useEntityActions<TEntity extends Entity = Entity, Data = any>(
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
const { entityType, path } = parseEntitiesPath(expandedPath);
|
const { entityType, path } = parseEntitiesPath(expandedPath);
|
||||||
|
|
||||||
const { deleteEntity, isLoading: deleteLoading } =
|
const { deleteEntity, isSubmitting: deleteSubmitting } =
|
||||||
useDeleteEntity(entityType, (entityId) => api.delete(endpoints.delete!.replaceAll(':id', entityId)));
|
useDeleteEntity(entityType, (entityId) => api.delete(endpoints.delete!.replaceAll(':id', entityId)));
|
||||||
|
|
||||||
const { createEntity, isSubmitting: createLoading } =
|
const { createEntity, isSubmitting: createSubmitting } =
|
||||||
useCreateEntity<TEntity, Data>(path, (data) => api.post(endpoints.post!, data), opts);
|
useCreateEntity<TEntity, Data>(path, (data) => api.post(endpoints.post!, data), opts);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
createEntity,
|
createEntity,
|
||||||
deleteEntity,
|
deleteEntity,
|
||||||
isLoading: createLoading || deleteLoading,
|
isSubmitting: createSubmitting || deleteSubmitting,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ const GroupActionButton = ({ group }: IGroupActionButton) => {
|
||||||
<Button
|
<Button
|
||||||
theme='primary'
|
theme='primary'
|
||||||
onClick={onJoinGroup}
|
onClick={onJoinGroup}
|
||||||
disabled={joinGroup.isLoading}
|
disabled={joinGroup.isSubmitting}
|
||||||
>
|
>
|
||||||
{group.locked
|
{group.locked
|
||||||
? <FormattedMessage id='group.join.private' defaultMessage='Request Access' />
|
? <FormattedMessage id='group.join.private' defaultMessage='Request Access' />
|
||||||
|
@ -103,7 +103,7 @@ const GroupActionButton = ({ group }: IGroupActionButton) => {
|
||||||
<Button
|
<Button
|
||||||
theme='secondary'
|
theme='secondary'
|
||||||
onClick={onCancelRequest}
|
onClick={onCancelRequest}
|
||||||
disabled={cancelRequest.isLoading}
|
disabled={cancelRequest.isSubmitting}
|
||||||
>
|
>
|
||||||
<FormattedMessage id='group.cancel_request' defaultMessage='Cancel Request' />
|
<FormattedMessage id='group.cancel_request' defaultMessage='Cancel Request' />
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -114,7 +114,7 @@ const GroupActionButton = ({ group }: IGroupActionButton) => {
|
||||||
<Button
|
<Button
|
||||||
theme='secondary'
|
theme='secondary'
|
||||||
onClick={onLeaveGroup}
|
onClick={onLeaveGroup}
|
||||||
disabled={leaveGroup.isLoading}
|
disabled={leaveGroup.isSubmitting}
|
||||||
>
|
>
|
||||||
<FormattedMessage id='group.leave' defaultMessage='Leave Group' />
|
<FormattedMessage id='group.leave' defaultMessage='Leave Group' />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
@ -7,14 +7,14 @@ import type { Group, GroupRelationship } from 'soapbox/schemas';
|
||||||
function useCancelMembershipRequest(group: Group) {
|
function useCancelMembershipRequest(group: Group) {
|
||||||
const me = useOwnAccount();
|
const me = useOwnAccount();
|
||||||
|
|
||||||
const { createEntity, isLoading } = useEntityActions<GroupRelationship>(
|
const { createEntity, isSubmitting } = useEntityActions<GroupRelationship>(
|
||||||
[Entities.GROUP_RELATIONSHIPS, group.id],
|
[Entities.GROUP_RELATIONSHIPS, group.id],
|
||||||
{ post: `/api/v1/groups/${group.id}/membership_requests/${me?.id}/reject` },
|
{ post: `/api/v1/groups/${group.id}/membership_requests/${me?.id}/reject` },
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mutate: createEntity,
|
mutate: createEntity,
|
||||||
isLoading,
|
isSubmitting,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,14 @@ import { useEntityActions } from 'soapbox/entity-store/hooks';
|
||||||
import type { Group } from 'soapbox/schemas';
|
import type { Group } from 'soapbox/schemas';
|
||||||
|
|
||||||
function useDeleteGroup() {
|
function useDeleteGroup() {
|
||||||
const { deleteEntity, isLoading } = useEntityActions<Group>(
|
const { deleteEntity, isSubmitting } = useEntityActions<Group>(
|
||||||
[Entities.GROUPS],
|
[Entities.GROUPS],
|
||||||
{ delete: '/api/v1/groups/:id' },
|
{ delete: '/api/v1/groups/:id' },
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mutate: deleteEntity,
|
mutate: deleteEntity,
|
||||||
isLoading,
|
isSubmitting,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import type { Group, GroupRelationship } from 'soapbox/schemas';
|
||||||
function useJoinGroup(group: Group) {
|
function useJoinGroup(group: Group) {
|
||||||
const { invalidate } = useGroups();
|
const { invalidate } = useGroups();
|
||||||
|
|
||||||
const { createEntity, isLoading } = useEntityActions<GroupRelationship>(
|
const { createEntity, isSubmitting } = useEntityActions<GroupRelationship>(
|
||||||
[Entities.GROUP_RELATIONSHIPS, group.id],
|
[Entities.GROUP_RELATIONSHIPS, group.id],
|
||||||
{ post: `/api/v1/groups/${group.id}/join` },
|
{ post: `/api/v1/groups/${group.id}/join` },
|
||||||
{ schema: groupRelationshipSchema },
|
{ schema: groupRelationshipSchema },
|
||||||
|
@ -17,7 +17,7 @@ function useJoinGroup(group: Group) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mutate: createEntity,
|
mutate: createEntity,
|
||||||
isLoading,
|
isSubmitting,
|
||||||
invalidate,
|
invalidate,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import type { Group, GroupRelationship } from 'soapbox/schemas';
|
||||||
function useLeaveGroup(group: Group) {
|
function useLeaveGroup(group: Group) {
|
||||||
const { invalidate } = useGroups();
|
const { invalidate } = useGroups();
|
||||||
|
|
||||||
const { createEntity, isLoading } = useEntityActions<GroupRelationship>(
|
const { createEntity, isSubmitting } = useEntityActions<GroupRelationship>(
|
||||||
[Entities.GROUP_RELATIONSHIPS, group.id],
|
[Entities.GROUP_RELATIONSHIPS, group.id],
|
||||||
{ post: `/api/v1/groups/${group.id}/leave` },
|
{ post: `/api/v1/groups/${group.id}/leave` },
|
||||||
{ schema: groupRelationshipSchema },
|
{ schema: groupRelationshipSchema },
|
||||||
|
@ -17,7 +17,7 @@ function useLeaveGroup(group: Group) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mutate: createEntity,
|
mutate: createEntity,
|
||||||
isLoading,
|
isSubmitting,
|
||||||
invalidate,
|
invalidate,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue