@adventurelabs/scout-core 1.4.22 → 1.4.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/useInfiniteQuery.js +16 -6
- package/dist/store/api.js +16 -6
- package/package.json +1 -1
|
@@ -443,7 +443,9 @@ export const useInfiniteFeedByHerd = (herdId, options) => {
|
|
|
443
443
|
useEffect(() => {
|
|
444
444
|
if (!currentQuery.data || currentQuery.isLoading)
|
|
445
445
|
return;
|
|
446
|
-
|
|
446
|
+
// Don't skip the first page after reset: only skip when we already have pages for this cursor
|
|
447
|
+
if (pages.length > 0 &&
|
|
448
|
+
feedCursorEq(lastAddedCursorRef.current ?? null, currentCursor))
|
|
447
449
|
return;
|
|
448
450
|
setPages((prev) => {
|
|
449
451
|
const existingPage = prev.find((p) => feedCursorEq(p.cursor, currentCursor));
|
|
@@ -451,7 +453,11 @@ export const useInfiniteFeedByHerd = (herdId, options) => {
|
|
|
451
453
|
const items = Array.isArray(currentQuery.data?.items)
|
|
452
454
|
? currentQuery.data.items
|
|
453
455
|
: [];
|
|
454
|
-
|
|
456
|
+
const limit = options.limit || 20;
|
|
457
|
+
// Only mark "last added" for full pages so partial/empty responses don't block a later merge
|
|
458
|
+
if (items.length >= limit) {
|
|
459
|
+
lastAddedCursorRef.current = currentCursor;
|
|
460
|
+
}
|
|
455
461
|
return [
|
|
456
462
|
...prev,
|
|
457
463
|
{ cursor: currentCursor, data: items },
|
|
@@ -459,7 +465,7 @@ export const useInfiniteFeedByHerd = (herdId, options) => {
|
|
|
459
465
|
}
|
|
460
466
|
return prev;
|
|
461
467
|
});
|
|
462
|
-
}, [currentQuery.data, currentQuery.isLoading, currentCursor]);
|
|
468
|
+
}, [currentQuery.data, currentQuery.isLoading, currentCursor, pages.length, options.limit]);
|
|
463
469
|
const loadMore = useCallback(() => {
|
|
464
470
|
if (currentQuery.data?.hasMore &&
|
|
465
471
|
currentQuery.data.nextCursor &&
|
|
@@ -524,7 +530,8 @@ export const useInfiniteFeedByDevice = (deviceId, options) => {
|
|
|
524
530
|
useEffect(() => {
|
|
525
531
|
if (!currentQuery.data || currentQuery.isLoading)
|
|
526
532
|
return;
|
|
527
|
-
if (
|
|
533
|
+
if (pages.length > 0 &&
|
|
534
|
+
feedCursorEq(lastAddedCursorRef.current ?? null, currentCursor))
|
|
528
535
|
return;
|
|
529
536
|
setPages((prev) => {
|
|
530
537
|
const existingPage = prev.find((p) => feedCursorEq(p.cursor, currentCursor));
|
|
@@ -532,7 +539,10 @@ export const useInfiniteFeedByDevice = (deviceId, options) => {
|
|
|
532
539
|
const items = Array.isArray(currentQuery.data?.items)
|
|
533
540
|
? currentQuery.data.items
|
|
534
541
|
: [];
|
|
535
|
-
|
|
542
|
+
const limit = options.limit || 20;
|
|
543
|
+
if (items.length >= limit) {
|
|
544
|
+
lastAddedCursorRef.current = currentCursor;
|
|
545
|
+
}
|
|
536
546
|
return [
|
|
537
547
|
...prev,
|
|
538
548
|
{ cursor: currentCursor, data: items },
|
|
@@ -540,7 +550,7 @@ export const useInfiniteFeedByDevice = (deviceId, options) => {
|
|
|
540
550
|
}
|
|
541
551
|
return prev;
|
|
542
552
|
});
|
|
543
|
-
}, [currentQuery.data, currentQuery.isLoading, currentCursor]);
|
|
553
|
+
}, [currentQuery.data, currentQuery.isLoading, currentCursor, pages.length, options.limit]);
|
|
544
554
|
const loadMore = useCallback(() => {
|
|
545
555
|
if (currentQuery.data?.hasMore &&
|
|
546
556
|
currentQuery.data.nextCursor &&
|
package/dist/store/api.js
CHANGED
|
@@ -455,7 +455,8 @@ export const scoutApi = createApi({
|
|
|
455
455
|
};
|
|
456
456
|
}
|
|
457
457
|
const rows = data || [];
|
|
458
|
-
|
|
458
|
+
// Full page (rows.length >= limit) means there might be more; only signal hasMore when we have a nextCursor
|
|
459
|
+
const hasMore = rows.length >= limit;
|
|
459
460
|
const resultRows = hasMore ? rows.slice(0, limit) : rows;
|
|
460
461
|
const uniqueFilePaths = Array.from(new Set(resultRows.flatMap((row) => {
|
|
461
462
|
const paths = [];
|
|
@@ -498,7 +499,7 @@ export const scoutApi = createApi({
|
|
|
498
499
|
: null,
|
|
499
500
|
}));
|
|
500
501
|
const last = resultRows[resultRows.length - 1];
|
|
501
|
-
const nextCursor =
|
|
502
|
+
const nextCursor = resultRows.length > 0
|
|
502
503
|
? {
|
|
503
504
|
timestamp: last.sort_ts ?? "",
|
|
504
505
|
id: last.sort_id ?? 0,
|
|
@@ -506,7 +507,11 @@ export const scoutApi = createApi({
|
|
|
506
507
|
}
|
|
507
508
|
: null;
|
|
508
509
|
return {
|
|
509
|
-
data: {
|
|
510
|
+
data: {
|
|
511
|
+
items,
|
|
512
|
+
nextCursor,
|
|
513
|
+
hasMore: nextCursor != null && hasMore,
|
|
514
|
+
},
|
|
510
515
|
};
|
|
511
516
|
}
|
|
512
517
|
catch (err) {
|
|
@@ -537,7 +542,8 @@ export const scoutApi = createApi({
|
|
|
537
542
|
};
|
|
538
543
|
}
|
|
539
544
|
const rows = data || [];
|
|
540
|
-
|
|
545
|
+
// Full page (rows.length >= limit) means there might be more; only signal hasMore when we have a nextCursor
|
|
546
|
+
const hasMore = rows.length >= limit;
|
|
541
547
|
const resultRows = hasMore ? rows.slice(0, limit) : rows;
|
|
542
548
|
const uniqueFilePaths = Array.from(new Set(resultRows.flatMap((row) => {
|
|
543
549
|
const paths = [];
|
|
@@ -580,7 +586,7 @@ export const scoutApi = createApi({
|
|
|
580
586
|
: null,
|
|
581
587
|
}));
|
|
582
588
|
const last = resultRows[resultRows.length - 1];
|
|
583
|
-
const nextCursor =
|
|
589
|
+
const nextCursor = resultRows.length > 0
|
|
584
590
|
? {
|
|
585
591
|
timestamp: last.sort_ts ?? "",
|
|
586
592
|
id: last.sort_id ?? 0,
|
|
@@ -588,7 +594,11 @@ export const scoutApi = createApi({
|
|
|
588
594
|
}
|
|
589
595
|
: null;
|
|
590
596
|
return {
|
|
591
|
-
data: {
|
|
597
|
+
data: {
|
|
598
|
+
items,
|
|
599
|
+
nextCursor,
|
|
600
|
+
hasMore: nextCursor != null && hasMore,
|
|
601
|
+
},
|
|
592
602
|
};
|
|
593
603
|
}
|
|
594
604
|
catch (err) {
|