This commit is contained in:
seb
2026-10-11 19:46:20 +02:00
parent cc914085fc
commit 36095d66c9
4 changed files with 16 additions and 8 deletions

View File

@@ -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));