diff --git a/app/soapbox/api/hooks/groups/useGroup.ts b/app/soapbox/api/hooks/groups/useGroup.ts index b66c0fee7..e963b951b 100644 --- a/app/soapbox/api/hooks/groups/useGroup.ts +++ b/app/soapbox/api/hooks/groups/useGroup.ts @@ -13,7 +13,7 @@ function useGroup(groupId: string, refetch = true) { () => api.get(`/api/v1/groups/${groupId}`), { schema: groupSchema, refetch }, ); - const { entity: relationship } = useGroupRelationship(groupId); + const { groupRelationship: relationship } = useGroupRelationship(groupId); return { ...result, diff --git a/app/soapbox/api/hooks/groups/useGroupLookup.ts b/app/soapbox/api/hooks/groups/useGroupLookup.ts index a9cb2b369..3e66f72c6 100644 --- a/app/soapbox/api/hooks/groups/useGroupLookup.ts +++ b/app/soapbox/api/hooks/groups/useGroupLookup.ts @@ -15,7 +15,7 @@ function useGroupLookup(slug: string) { { schema: groupSchema, enabled: !!slug }, ); - const { entity: relationship } = useGroupRelationship(group?.id); + const { groupRelationship: relationship } = useGroupRelationship(group?.id); return { ...result, diff --git a/app/soapbox/api/hooks/groups/useGroupMembershipRequests.ts b/app/soapbox/api/hooks/groups/useGroupMembershipRequests.ts index a6e068091..64ab26d7c 100644 --- a/app/soapbox/api/hooks/groups/useGroupMembershipRequests.ts +++ b/app/soapbox/api/hooks/groups/useGroupMembershipRequests.ts @@ -12,7 +12,7 @@ function useGroupMembershipRequests(groupId: string) { const api = useApi(); const path: ExpandedEntitiesPath = [Entities.ACCOUNTS, 'membership_requests', groupId]; - const { entity: relationship } = useGroupRelationship(groupId); + const { groupRelationship: relationship } = useGroupRelationship(groupId); const { entities, invalidate, fetchEntities, ...rest } = useEntities( path, diff --git a/app/soapbox/api/hooks/groups/useGroupRelationship.ts b/app/soapbox/api/hooks/groups/useGroupRelationship.ts index c6e51d869..95193b865 100644 --- a/app/soapbox/api/hooks/groups/useGroupRelationship.ts +++ b/app/soapbox/api/hooks/groups/useGroupRelationship.ts @@ -1,18 +1,15 @@ -import { useEffect } from 'react'; import { z } from 'zod'; -import { fetchGroupRelationshipsSuccess } from 'soapbox/actions/groups'; import { Entities } from 'soapbox/entity-store/entities'; import { useEntity } from 'soapbox/entity-store/hooks'; -import { useApi, useAppDispatch } from 'soapbox/hooks'; +import { useApi } from 'soapbox/hooks'; import { type GroupRelationship, groupRelationshipSchema } from 'soapbox/schemas'; function useGroupRelationship(groupId: string | undefined) { const api = useApi(); - const dispatch = useAppDispatch(); const { entity: groupRelationship, ...result } = useEntity( - [Entities.GROUP_RELATIONSHIPS, groupId as string], + [Entities.GROUP_RELATIONSHIPS, groupId!], () => api.get(`/api/v1/groups/relationships?id[]=${groupId}`), { enabled: !!groupId, @@ -20,14 +17,8 @@ function useGroupRelationship(groupId: string | undefined) { }, ); - useEffect(() => { - if (groupRelationship?.id) { - dispatch(fetchGroupRelationshipsSuccess([groupRelationship])); - } - }, [groupRelationship?.id]); - return { - entity: groupRelationship, + groupRelationship, ...result, }; } diff --git a/app/soapbox/components/status-action-bar.tsx b/app/soapbox/components/status-action-bar.tsx index 0e6a9b894..b071cc945 100644 --- a/app/soapbox/components/status-action-bar.tsx +++ b/app/soapbox/components/status-action-bar.tsx @@ -14,6 +14,7 @@ import { initMuteModal } from 'soapbox/actions/mutes'; import { initReport, ReportableEntities } from 'soapbox/actions/reports'; import { deleteStatus, editStatus, toggleMuteStatus } from 'soapbox/actions/statuses'; import { deleteFromTimelines } from 'soapbox/actions/timelines'; +import { useGroupRelationship } from 'soapbox/api/hooks'; import { useDeleteGroupStatus } from 'soapbox/api/hooks/groups/useDeleteGroupStatus'; import DropdownMenu from 'soapbox/components/dropdown-menu'; import StatusActionButton from 'soapbox/components/status-action-button'; @@ -115,7 +116,7 @@ const StatusActionBar: React.FC = ({ const dispatch = useAppDispatch(); const me = useAppSelector(state => state.me); - const groupRelationship = useAppSelector(state => status.group ? state.group_relationships.get((status.group as Group).id) : null); + const { groupRelationship } = useGroupRelationship(status.group?.id); const features = useFeatures(); const settings = useSettings(); const soapboxConfig = useSoapboxConfig();