From 74ebd560e6b0d285a05a3dc1aedd3a63e47cf05c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 15 Mar 2023 14:19:13 -0500 Subject: [PATCH] Revert useEntity array changes, do that in the schema parser --- app/soapbox/entity-store/hooks/useEntity.ts | 2 +- app/soapbox/hooks/useGroups.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/soapbox/entity-store/hooks/useEntity.ts b/app/soapbox/entity-store/hooks/useEntity.ts index 3c4b9cce7c..1dad1ff1e3 100644 --- a/app/soapbox/entity-store/hooks/useEntity.ts +++ b/app/soapbox/entity-store/hooks/useEntity.ts @@ -39,7 +39,7 @@ function useEntity( const fetchEntity = () => { setIsFetching(true); api.get(endpoint).then(({ data }) => { - const entity = schema.parse(Array.isArray(data) ? data[0] : data); + const entity = schema.parse(data); dispatch(importEntities([entity], entityType)); setIsFetching(false); }).catch(() => { diff --git a/app/soapbox/hooks/useGroups.ts b/app/soapbox/hooks/useGroups.ts index 7ce158c979..865896e24f 100644 --- a/app/soapbox/hooks/useGroups.ts +++ b/app/soapbox/hooks/useGroups.ts @@ -1,3 +1,5 @@ +import { z } from 'zod'; + import { Entities } from 'soapbox/entity-store/entities'; import { useEntities, useEntity } from 'soapbox/entity-store/hooks'; import { groupSchema, Group } from 'soapbox/schemas/group'; @@ -40,7 +42,7 @@ function useGroupRelationship(groupId: string) { return useEntity( [Entities.GROUP_RELATIONSHIPS, groupId], `/api/v1/groups/relationships?id[]=${groupId}`, - { schema: groupRelationshipSchema }, + { schema: z.array(groupRelationshipSchema).transform(arr => arr[0]) }, ); }