All files / src/components/pages/group-list/group-list-infinite-scroll index.tsx

0% Statements 0/48
0% Branches 0/1
0% Functions 0/1
0% Lines 0/48

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                                                                                                 
import { type RefObject } from 'react';

interface GroupListInfiniteScrollProps {
  sentinelRef: RefObject<HTMLDivElement | null>;
  hasNextPage: boolean;
  isFetchingNextPage: boolean;
  completedMessage: string;
  hasError: boolean;
}

export const GroupListInfiniteScroll = ({
  sentinelRef,
  hasNextPage,
  isFetchingNextPage,
  completedMessage,
  hasError,
}: GroupListInfiniteScrollProps) => {
  if (hasNextPage && !hasError) {
    return (
      <>
        <div ref={sentinelRef} aria-hidden='true' className='h-1' />
        {isFetchingNextPage && (
          <div
            className='py-8 text-center text-gray-500'
            aria-label='더 많은 모임을 불러오는 중입니다'
            aria-live='polite'
            role='status'
          >
            <div className='flex items-center justify-center gap-2'>
              <div className='border-t-mint-500 h-5 w-5 animate-spin rounded-full border-2 border-gray-300' />
              <span>더 많은 모임을 불러오는 중...</span>
            </div>
          </div>
        )}
      </>
    );
  }

  if (!hasNextPage && !hasError) {
    return (
      <div className='py-8 text-center text-gray-500' aria-live='polite' role='status'>
        {completedMessage}
      </div>
    );
  }

  return null;
};