StatusActionBar: use GroupRelationship from entity store

environments/review-group-hook-n3r89k/deployments/3533
Alex Gleason 2023-06-26 12:09:30 -05:00
rodzic e07412f872
commit a8792f9a02
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
5 zmienionych plików z 8 dodań i 16 usunięć

Wyświetl plik

@ -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,

Wyświetl plik

@ -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,

Wyświetl plik

@ -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,

Wyświetl plik

@ -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<GroupRelationship>(
[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,
};
}

Wyświetl plik

@ -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<IStatusActionBar> = ({
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();