sforkowany z mirror/soapbox
Revert useEntity array changes, do that in the schema parser
rodzic
6b30671875
commit
74ebd560e6
|
@ -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(() => {
|
||||||
|
|
|
@ -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]) },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue