From 75b0262f9a68904caa9d6890d0b9079c13d64f63 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 22 Mar 2023 21:24:53 -0500 Subject: [PATCH] Move pendingCount logic to useEntities --- app/soapbox/entity-store/hooks/useEntities.ts | 2 ++ app/soapbox/features/group/group-members.tsx | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/soapbox/entity-store/hooks/useEntities.ts b/app/soapbox/entity-store/hooks/useEntities.ts index 6c8511e65..8e679709a 100644 --- a/app/soapbox/entity-store/hooks/useEntities.ts +++ b/app/soapbox/entity-store/hooks/useEntities.ts @@ -129,6 +129,8 @@ function useEntities( isFetching, isLoading: isFetching && entities.length === 0, invalidate, + /** The `X-Total-Count` from the API if available, or the length of items in the store. */ + count: typeof totalCount === 'number' ? totalCount : entities.length, }; } diff --git a/app/soapbox/features/group/group-members.tsx b/app/soapbox/features/group/group-members.tsx index f84ccd0aa..39fbd940f 100644 --- a/app/soapbox/features/group/group-members.tsx +++ b/app/soapbox/features/group/group-members.tsx @@ -25,7 +25,7 @@ const GroupMembers: React.FC = (props) => { const { groupMembers: owners, isFetching: isFetchingOwners } = useGroupMembers(groupId, GroupRoles.OWNER); const { groupMembers: admins, isFetching: isFetchingAdmins } = useGroupMembers(groupId, GroupRoles.ADMIN); const { groupMembers: users, isFetching: isFetchingUsers, fetchNextPage, hasNextPage } = useGroupMembers(groupId, GroupRoles.USER); - const { accounts: pending, isFetching: isFetchingPending, totalCount: pendingTotalCount } = useGroupMembershipRequests(groupId); + const { isFetching: isFetchingPending, count: pendingCount } = useGroupMembershipRequests(groupId); const isLoading = isFetchingGroup || isFetchingOwners || isFetchingAdmins || isFetchingUsers || isFetchingPending; @@ -35,9 +35,6 @@ const GroupMembers: React.FC = (props) => { ...users, ], [owners, admins, users]); - // If the API gives us `X-Total-Count`, use it. Otherwise fallback to the number in the store. - const pendingCount = typeof pendingTotalCount === 'number' ? pendingTotalCount : pending.length; - return ( <>