Revert useEntity array changes, do that in the schema parser

develop^2
Alex Gleason 2023-03-15 14:19:13 -05:00
rodzic 6b30671875
commit 74ebd560e6
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 4 dodań i 2 usunięć

Wyświetl plik

@ -39,7 +39,7 @@ function useEntity<TEntity extends Entity>(
const fetchEntity = () => { const fetchEntity = () => {
setIsFetching(true); setIsFetching(true);
api.get(endpoint).then(({ data }) => { api.get(endpoint).then(({ data }) => {
const entity = schema.parse(Array.isArray(data) ? data[0] : data); const entity = schema.parse(data);
dispatch(importEntities([entity], entityType)); dispatch(importEntities([entity], entityType));
setIsFetching(false); setIsFetching(false);
}).catch(() => { }).catch(() => {

Wyświetl plik

@ -1,3 +1,5 @@
import { z } from 'zod';
import { Entities } from 'soapbox/entity-store/entities'; import { Entities } from 'soapbox/entity-store/entities';
import { useEntities, useEntity } from 'soapbox/entity-store/hooks'; import { useEntities, useEntity } from 'soapbox/entity-store/hooks';
import { groupSchema, Group } from 'soapbox/schemas/group'; import { groupSchema, Group } from 'soapbox/schemas/group';
@ -40,7 +42,7 @@ function useGroupRelationship(groupId: string) {
return useEntity<GroupRelationship>( return useEntity<GroupRelationship>(
[Entities.GROUP_RELATIONSHIPS, groupId], [Entities.GROUP_RELATIONSHIPS, groupId],
`/api/v1/groups/relationships?id[]=${groupId}`, `/api/v1/groups/relationships?id[]=${groupId}`,
{ schema: groupRelationshipSchema }, { schema: z.array(groupRelationshipSchema).transform(arr => arr[0]) },
); );
} }