All files / src/components/pages/schedule/schedule-tabs/past index.tsx

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

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 50 51 52 53 54 55 56 57 58 59 60 61                                                                                                                         
'use client';

import { API } from '@/api';
import { useInfiniteScroll } from '@/hooks/use-group/use-group-infinite-list';
import { useIntersectionObserver } from '@/hooks/use-intersection-observer';
import { GROUP_LIST_PAGE_SIZE, INTERSECTION_OBSERVER_THRESHOLD } from '@/lib/constants/group-list';
import { groupKeys } from '@/lib/query-key/query-key-group';
import { GroupListItemResponse } from '@/types/service/group';

import { ScheduleList } from '../../schedule-list/index';

export const Past = () => {
  const queryKey = groupKeys.myGroupsList('past') as ['myGroups', 'past'];

  const {
    items,
    error,
    fetchNextPage,
    hasNextPage,
    isFetchingNextPage,
    isLoading,
    completedMessage,
    refetch,
  } = useInfiniteScroll<GroupListItemResponse, typeof queryKey>({
    queryFn: async ({ cursor, size }) => {
      return await API.groupService.getMyGroups({ type: 'past', cursor, size });
    },
    queryKey,
    pageSize: GROUP_LIST_PAGE_SIZE,
    errorMessage: '모임 이력을 불러오는데 실패했습니다.',
    completedMessage: '모든 모임 이력을 불러왔습니다.',
  });

  const sentinelRef = useIntersectionObserver({
    onIntersect: () => {
      if (hasNextPage && !isFetchingNextPage) {
        fetchNextPage();
      }
    },
    enabled: hasNextPage && error === null,
    threshold: INTERSECTION_OBSERVER_THRESHOLD,
  });

  return (
    <ScheduleList
      refetch={refetch}
      completedMessage={completedMessage}
      emptyStatePath='/'
      emptyStateType='past'
      error={error}
      group={items}
      hasNextPage={hasNextPage}
      isFetchingNextPage={isFetchingNextPage}
      isLoading={isLoading}
      sentinelRef={sentinelRef}
      showActions={false}
      tabType='past'
    />
  );
};