u
This commit is contained in:
@@ -144,7 +144,7 @@ const actions = {
|
||||
*
|
||||
* @returns {Promise<Order[]>}
|
||||
*/
|
||||
loadMore() {
|
||||
loadMore(minNeeded) {
|
||||
const { items, total, status, loadingMore } = automat.state;
|
||||
if (status !== 'ready' || loadingMore) return Promise.resolve(items);
|
||||
if (total > 0 && items.length >= total) return Promise.resolve(items);
|
||||
@@ -152,7 +152,11 @@ const actions = {
|
||||
|
||||
automat.setState({ loadingMore: true });
|
||||
const offset = items.length;
|
||||
inflightMore = fetchOrdersPage(offset, FETCH_PAGE_SIZE)
|
||||
const fetchLimit =
|
||||
minNeeded && minNeeded > offset
|
||||
? Math.max(FETCH_PAGE_SIZE, minNeeded - offset)
|
||||
: FETCH_PAGE_SIZE;
|
||||
inflightMore = fetchOrdersPage(offset, fetchLimit)
|
||||
.then(({ orders: nextBatch, total: newTotal }) => {
|
||||
const existingIds = new Set(automat.state.items.map((o) => o.id));
|
||||
const uniqueNext = nextBatch.filter((o) => !existingIds.has(o.id));
|
||||
|
||||
Reference in New Issue
Block a user