-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 전체 방 조회 msw API 및 쿼리 작성 * feat: 방 전체 조회 API 연결 * feat: 옵저버 제외한 무한 fetching 기능 추가 * feat: 로딩 fallback 추가 * feat: 무한스크롤 쿼리 로직 분리 * feat: 무한스크롤 커스텀 훅 구현 및 기능 연결 * feat: 옵저버 훅 및 UI 수정 * feat: 코드 리뷰 반영
- Loading branch information
Showing
14 changed files
with
993 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
|
||
interface ResultListFallbackProps { | ||
size?: number; | ||
} | ||
|
||
const ResultListFallback = ({ size = 10 }: ResultListFallbackProps) => { | ||
return ( | ||
<div className="flex flex-col gap-2 opacity-60"> | ||
{Array.from({ length: size }, (_, index) => ( | ||
<div | ||
key={index} | ||
className="my-1 h-24 w-full animate-pulse rounded-2xl bg-light-gray dark:bg-dark-gray" | ||
></div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ResultListFallback; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useCallback, useEffect, useRef } from 'react'; | ||
|
||
interface ObserverOptions { | ||
root?: Element | null; | ||
rootMargin?: string; | ||
threshold?: number; | ||
onObserve: VoidFunction; | ||
} | ||
|
||
const useIntersectionObserver = ({ | ||
onObserve, | ||
...options | ||
}: ObserverOptions) => { | ||
const intersectionRef = useRef<HTMLDivElement>(null); | ||
|
||
const handleIntersect: IntersectionObserverCallback = useCallback( | ||
(entries) => { | ||
entries.forEach((entry) => { | ||
if (entry.isIntersecting) { | ||
onObserve(); | ||
} | ||
}); | ||
}, | ||
[onObserve] | ||
); | ||
|
||
useEffect(() => { | ||
const observer = new IntersectionObserver(handleIntersect, options); | ||
const intersectionElement = intersectionRef.current; | ||
|
||
intersectionElement && observer.observe(intersectionElement); | ||
|
||
return () => { | ||
intersectionElement && observer.unobserve(intersectionElement); | ||
}; | ||
}, [handleIntersect, options]); | ||
|
||
return intersectionRef; | ||
}; | ||
|
||
export default useIntersectionObserver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as useInfiniteSearch } from './useInfiniteSearch'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useSuspenseInfiniteQuery } from '@tanstack/react-query'; | ||
import { RoomSelectType } from '@/core/types'; | ||
import roomAPI from '../functions/roomAPI'; | ||
|
||
const useInfiniteSearch = ({ | ||
type, | ||
size | ||
}: { | ||
type: RoomSelectType; | ||
size: number; | ||
}) => { | ||
return useSuspenseInfiniteQuery({ | ||
queryKey: ['rooms', type], | ||
|
||
queryFn: ({ pageParam }) => | ||
roomAPI.getRoomsAll({ page: pageParam, type, size }), | ||
|
||
initialPageParam: 1, | ||
|
||
getNextPageParam: (lastPage, allPages, lastPageParam) => | ||
lastPage.length < size ? null : lastPageParam + 1, | ||
|
||
select: ({ pages }) => pages | ||
}); | ||
}; | ||
|
||
export default useInfiniteSearch; |
Oops, something went wrong.