@adventurelabs/scout-core 1.4.25 → 1.4.27

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.
@@ -417,9 +417,10 @@ const feedCursorEq = (a, b) => {
417
417
  export const useInfiniteFeedByHerd = (herdId, options) => {
418
418
  const [pages, setPages] = useState([]);
419
419
  const [currentCursor, setCurrentCursor] = useState(null);
420
+ // Match dummy: use state so hasMore/nextCursor trigger re-renders and loadMore sees latest (ref was not updating UI)
421
+ const [lastResult, setLastResult] = useState(null);
420
422
  const prevHerdIdRef = useRef(undefined);
421
423
  const lastAddedCursorRef = useRef(undefined);
422
- const lastResultRef = useRef(null);
423
424
  const pagesLengthRef = useRef(0);
424
425
  const currentQuery = useGetFeedInfiniteByHerdQuery({
425
426
  herdId,
@@ -437,7 +438,7 @@ export const useInfiniteFeedByHerd = (herdId, options) => {
437
438
  setPages([]);
438
439
  setCurrentCursor(null);
439
440
  lastAddedCursorRef.current = undefined;
440
- lastResultRef.current = null;
441
+ setLastResult(null);
441
442
  }
442
443
  prevHerdIdRef.current = herdId;
443
444
  }, [herdId]);
@@ -456,11 +457,11 @@ export const useInfiniteFeedByHerd = (herdId, options) => {
456
457
  ? currentQuery.data.items
457
458
  : [];
458
459
  const limit = options.limit || 20;
459
- // Store hasMore/nextCursor from this response so loadMore can use it (like dummy's currentResult)
460
- lastResultRef.current = {
460
+ // Match dummy: set state so UI re-renders with hasMore and loadMore sees latest nextCursor
461
+ setLastResult({
461
462
  hasMore: currentQuery.data.hasMore ?? false,
462
463
  nextCursor: currentQuery.data.nextCursor ?? null,
463
- };
464
+ });
464
465
  setPages((prev) => {
465
466
  const existingPage = prev.find((p) => feedCursorEq(p.cursor, currentCursor));
466
467
  if (!existingPage) {
@@ -476,18 +477,17 @@ export const useInfiniteFeedByHerd = (herdId, options) => {
476
477
  });
477
478
  }, [currentQuery.data, currentQuery.isLoading, currentCursor, pages.length, options.limit]);
478
479
  const loadMore = useCallback(() => {
479
- const result = lastResultRef.current;
480
- if (result?.hasMore &&
481
- result.nextCursor != null &&
480
+ if (lastResult?.hasMore &&
481
+ lastResult.nextCursor != null &&
482
482
  !currentQuery.isLoading) {
483
- setCurrentCursor(result.nextCursor);
483
+ setCurrentCursor(lastResult.nextCursor);
484
484
  }
485
- }, [currentQuery.isLoading]);
485
+ }, [lastResult, currentQuery.isLoading]);
486
486
  const refetch = useCallback(() => {
487
487
  setPages([]);
488
488
  setCurrentCursor(null);
489
489
  lastAddedCursorRef.current = undefined;
490
- lastResultRef.current = null;
490
+ setLastResult(null);
491
491
  currentQuery.refetch();
492
492
  }, [currentQuery]);
493
493
  const allItems = useMemo(() => {
@@ -504,7 +504,7 @@ export const useInfiniteFeedByHerd = (herdId, options) => {
504
504
  items: allItems,
505
505
  isLoading: currentQuery.isLoading && pages.length === 0,
506
506
  isLoadingMore: currentQuery.isLoading && pages.length > 0,
507
- hasMore: (lastResultRef.current?.hasMore ??
507
+ hasMore: (lastResult?.hasMore ??
508
508
  (currentCursor !== null && pages.length > 0)) ??
509
509
  false,
510
510
  loadMore,
@@ -515,9 +515,9 @@ export const useInfiniteFeedByHerd = (herdId, options) => {
515
515
  export const useInfiniteFeedByDevice = (deviceId, options) => {
516
516
  const [pages, setPages] = useState([]);
517
517
  const [currentCursor, setCurrentCursor] = useState(null);
518
+ const [lastResult, setLastResult] = useState(null);
518
519
  const prevDeviceIdRef = useRef(undefined);
519
520
  const lastAddedCursorRef = useRef(undefined);
520
- const lastResultRef = useRef(null);
521
521
  const pagesLengthRef = useRef(0);
522
522
  const currentQuery = useGetFeedInfiniteByDeviceQuery({
523
523
  deviceId,
@@ -535,7 +535,7 @@ export const useInfiniteFeedByDevice = (deviceId, options) => {
535
535
  setPages([]);
536
536
  setCurrentCursor(null);
537
537
  lastAddedCursorRef.current = undefined;
538
- lastResultRef.current = null;
538
+ setLastResult(null);
539
539
  }
540
540
  prevDeviceIdRef.current = deviceId;
541
541
  }, [deviceId]);
@@ -549,6 +549,10 @@ export const useInfiniteFeedByDevice = (deviceId, options) => {
549
549
  if (pagesLengthRef.current > 0 &&
550
550
  feedCursorEq(lastAddedCursorRef.current ?? null, currentCursor))
551
551
  return;
552
+ setLastResult({
553
+ hasMore: currentQuery.data?.hasMore ?? false,
554
+ nextCursor: currentQuery.data?.nextCursor ?? null,
555
+ });
552
556
  setPages((prev) => {
553
557
  const existingPage = prev.find((p) => feedCursorEq(p.cursor, currentCursor));
554
558
  if (!existingPage) {
@@ -559,10 +563,6 @@ export const useInfiniteFeedByDevice = (deviceId, options) => {
559
563
  if (items.length >= limit) {
560
564
  lastAddedCursorRef.current = currentCursor;
561
565
  }
562
- lastResultRef.current = {
563
- hasMore: currentQuery.data?.hasMore ?? false,
564
- nextCursor: currentQuery.data?.nextCursor ?? null,
565
- };
566
566
  return [
567
567
  ...prev,
568
568
  { cursor: currentCursor, data: items },
@@ -572,18 +572,17 @@ export const useInfiniteFeedByDevice = (deviceId, options) => {
572
572
  });
573
573
  }, [currentQuery.data, currentQuery.isLoading, currentCursor, pages.length, options.limit]);
574
574
  const loadMore = useCallback(() => {
575
- const result = lastResultRef.current;
576
- if (result?.hasMore &&
577
- result.nextCursor != null &&
575
+ if (lastResult?.hasMore &&
576
+ lastResult.nextCursor != null &&
578
577
  !currentQuery.isLoading) {
579
- setCurrentCursor(result.nextCursor);
578
+ setCurrentCursor(lastResult.nextCursor);
580
579
  }
581
- }, [currentQuery.isLoading]);
580
+ }, [lastResult, currentQuery.isLoading]);
582
581
  const refetch = useCallback(() => {
583
582
  setPages([]);
584
583
  setCurrentCursor(null);
585
584
  lastAddedCursorRef.current = undefined;
586
- lastResultRef.current = null;
585
+ setLastResult(null);
587
586
  currentQuery.refetch();
588
587
  }, [currentQuery]);
589
588
  const allItems = useMemo(() => {
@@ -600,7 +599,7 @@ export const useInfiniteFeedByDevice = (deviceId, options) => {
600
599
  items: allItems,
601
600
  isLoading: currentQuery.isLoading && pages.length === 0,
602
601
  isLoadingMore: currentQuery.isLoading && pages.length > 0,
603
- hasMore: (lastResultRef.current?.hasMore ??
602
+ hasMore: (lastResult?.hasMore ??
604
603
  (currentCursor !== null && pages.length > 0)) ??
605
604
  false,
606
605
  loadMore,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.4.25",
3
+ "version": "1.4.27",
4
4
  "description": "Core utilities and helpers for Adventure Labs Scout applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",