From 39f2734bd478eacdf7ff60088bb21468fe45f2cc Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Mon, 10 Apr 2023 13:06:06 -0400 Subject: [PATCH] Fix replying to status from Group --- app/soapbox/actions/statuses.ts | 4 ++++ app/soapbox/hooks/api/groups/useGroups.ts | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/soapbox/actions/statuses.ts b/app/soapbox/actions/statuses.ts index b14108de24..ab6a855eea 100644 --- a/app/soapbox/actions/statuses.ts +++ b/app/soapbox/actions/statuses.ts @@ -5,6 +5,7 @@ import { shouldHaveCard } from 'soapbox/utils/status'; import api, { getNextLink } from '../api'; import { setComposeToStatus } from './compose'; +import { fetchGroupRelationships } from './groups'; import { importFetchedStatus, importFetchedStatuses } from './importer'; import { openModal } from './modals'; import { deleteFromTimelines } from './timelines'; @@ -124,6 +125,9 @@ const fetchStatus = (id: string) => { return api(getState).get(`/api/v1/statuses/${id}`).then(({ data: status }) => { dispatch(importFetchedStatus(status)); + if (status.group) { + dispatch(fetchGroupRelationships([status.group.id])); + } dispatch({ type: STATUS_FETCH_SUCCESS, status, skipLoading }); return status; }).catch(error => { diff --git a/app/soapbox/hooks/api/groups/useGroups.ts b/app/soapbox/hooks/api/groups/useGroups.ts index f77f66cdcd..9db3001ce8 100644 --- a/app/soapbox/hooks/api/groups/useGroups.ts +++ b/app/soapbox/hooks/api/groups/useGroups.ts @@ -1,8 +1,10 @@ +import { useEffect } from 'react'; import { z } from 'zod'; +import { fetchGroupRelationshipsSuccess } from 'soapbox/actions/groups'; import { Entities } from 'soapbox/entity-store/entities'; import { useEntities, useEntity } from 'soapbox/entity-store/hooks'; -import { useApi } from 'soapbox/hooks'; +import { useApi, useAppDispatch } from 'soapbox/hooks'; import { groupSchema, Group } from 'soapbox/schemas/group'; import { groupRelationshipSchema, GroupRelationship } from 'soapbox/schemas/group-relationship'; @@ -48,12 +50,24 @@ function useGroup(groupId: string, refetch = true) { function useGroupRelationship(groupId: string) { const api = useApi(); + const dispatch = useAppDispatch(); - return useEntity( + const { entity: groupRelationship, ...result } = useEntity( [Entities.GROUP_RELATIONSHIPS, groupId], () => api.get(`/api/v1/groups/relationships?id[]=${groupId}`), { schema: z.array(groupRelationshipSchema).transform(arr => arr[0]) }, ); + + useEffect(() => { + if (groupRelationship?.id) { + dispatch(fetchGroupRelationshipsSuccess([groupRelationship])); + } + }, [groupRelationship?.id]); + + return { + entity: groupRelationship, + ...result, + }; } function useGroupRelationships(groupIds: string[]) {