mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Fixed loading 0th page of recommendations (#18116)
no issue When the total numbers of pages was 0, the pagination hook would try to load the 0th page which would cause an API error.
This commit is contained in:
parent
908e02c016
commit
0559c8ba64
1 changed files with 2 additions and 2 deletions
|
@ -24,7 +24,7 @@ export const usePagination = ({limit, meta, page, setPage}: {meta?: Meta, limit:
|
||||||
if (meta) {
|
if (meta) {
|
||||||
setPrevMeta(meta);
|
setPrevMeta(meta);
|
||||||
|
|
||||||
if (meta.pagination.pages < page) {
|
if (meta.pagination.pages > 0 && meta.pagination.pages < page) {
|
||||||
// We probably deleted an item when on the last page: go one page back automatically
|
// We probably deleted an item when on the last page: go one page back automatically
|
||||||
setPage(meta.pagination.pages);
|
setPage(meta.pagination.pages);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ export const usePagination = ({limit, meta, page, setPage}: {meta?: Meta, limit:
|
||||||
pages: prevMeta?.pagination.pages ?? null,
|
pages: prevMeta?.pagination.pages ?? null,
|
||||||
limit: prevMeta?.pagination.limit ?? limit,
|
limit: prevMeta?.pagination.limit ?? limit,
|
||||||
total: prevMeta?.pagination.total ?? null,
|
total: prevMeta?.pagination.total ?? null,
|
||||||
nextPage: () => setPage(Math.min(page + 1, prevMeta?.pagination.pages ?? page)),
|
nextPage: () => setPage(Math.min(page + 1, prevMeta?.pagination.pages ? prevMeta.pagination.pages : page)),
|
||||||
prevPage: () => setPage(Math.max(1, page - 1))
|
prevPage: () => setPage(Math.max(1, page - 1))
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue