kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Merge branch 'drop-invalid-count' into 'develop'
useEntities: drop X-Total-Count if it's less than the number of entities in the response See merge request soapbox-pub/soapbox!2419environments/review-develop-3zknud/deployments/3104
commit
6ff1caa2fb
|
@ -65,11 +65,12 @@ function useEntities<TEntity extends Entity>(
|
||||||
const schema = opts.schema || z.custom<TEntity>();
|
const schema = opts.schema || z.custom<TEntity>();
|
||||||
const entities = filteredArray(schema).parse(response.data);
|
const entities = filteredArray(schema).parse(response.data);
|
||||||
const parsedCount = realNumberSchema.safeParse(response.headers['x-total-count']);
|
const parsedCount = realNumberSchema.safeParse(response.headers['x-total-count']);
|
||||||
|
const totalCount = parsedCount.success ? parsedCount.data : undefined;
|
||||||
|
|
||||||
dispatch(entitiesFetchSuccess(entities, entityType, listKey, {
|
dispatch(entitiesFetchSuccess(entities, entityType, listKey, {
|
||||||
next: getNextLink(response),
|
next: getNextLink(response),
|
||||||
prev: getPrevLink(response),
|
prev: getPrevLink(response),
|
||||||
totalCount: parsedCount.success ? parsedCount.data : undefined,
|
totalCount: Number(totalCount) >= entities.length ? totalCount : undefined,
|
||||||
fetching: false,
|
fetching: false,
|
||||||
fetched: true,
|
fetched: true,
|
||||||
error: null,
|
error: null,
|
||||||
|
|
Ładowanie…
Reference in New Issue