@adventurelabs/scout-core 1.4.27 → 1.4.31
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.
|
@@ -457,11 +457,11 @@ export const useInfiniteFeedByHerd = (herdId, options) => {
|
|
|
457
457
|
? currentQuery.data.items
|
|
458
458
|
: [];
|
|
459
459
|
const limit = options.limit || 20;
|
|
460
|
-
|
|
461
|
-
setLastResult({
|
|
460
|
+
const nextResult = {
|
|
462
461
|
hasMore: currentQuery.data.hasMore ?? false,
|
|
463
462
|
nextCursor: currentQuery.data.nextCursor ?? null,
|
|
464
|
-
}
|
|
463
|
+
};
|
|
464
|
+
setLastResult(nextResult);
|
|
465
465
|
setPages((prev) => {
|
|
466
466
|
const existingPage = prev.find((p) => feedCursorEq(p.cursor, currentCursor));
|
|
467
467
|
if (!existingPage) {
|
|
@@ -475,6 +475,11 @@ export const useInfiniteFeedByHerd = (herdId, options) => {
|
|
|
475
475
|
}
|
|
476
476
|
return prev;
|
|
477
477
|
});
|
|
478
|
+
// Request next page when this response has more (avoids relying on consumer's
|
|
479
|
+
// IntersectionObserver when sentinel is already in view and callback doesn't re-fire).
|
|
480
|
+
if (nextResult.hasMore && nextResult.nextCursor != null) {
|
|
481
|
+
setCurrentCursor(nextResult.nextCursor);
|
|
482
|
+
}
|
|
478
483
|
}, [currentQuery.data, currentQuery.isLoading, currentCursor, pages.length, options.limit]);
|
|
479
484
|
const loadMore = useCallback(() => {
|
|
480
485
|
if (lastResult?.hasMore &&
|
|
@@ -549,10 +554,11 @@ export const useInfiniteFeedByDevice = (deviceId, options) => {
|
|
|
549
554
|
if (pagesLengthRef.current > 0 &&
|
|
550
555
|
feedCursorEq(lastAddedCursorRef.current ?? null, currentCursor))
|
|
551
556
|
return;
|
|
552
|
-
|
|
557
|
+
const nextResult = {
|
|
553
558
|
hasMore: currentQuery.data?.hasMore ?? false,
|
|
554
559
|
nextCursor: currentQuery.data?.nextCursor ?? null,
|
|
555
|
-
}
|
|
560
|
+
};
|
|
561
|
+
setLastResult(nextResult);
|
|
556
562
|
setPages((prev) => {
|
|
557
563
|
const existingPage = prev.find((p) => feedCursorEq(p.cursor, currentCursor));
|
|
558
564
|
if (!existingPage) {
|
|
@@ -570,6 +576,9 @@ export const useInfiniteFeedByDevice = (deviceId, options) => {
|
|
|
570
576
|
}
|
|
571
577
|
return prev;
|
|
572
578
|
});
|
|
579
|
+
if (nextResult.hasMore && nextResult.nextCursor != null) {
|
|
580
|
+
setCurrentCursor(nextResult.nextCursor);
|
|
581
|
+
}
|
|
573
582
|
}, [currentQuery.data, currentQuery.isLoading, currentCursor, pages.length, options.limit]);
|
|
574
583
|
const loadMore = useCallback(() => {
|
|
575
584
|
if (lastResult?.hasMore &&
|