-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 전체 방 조회 API 연결 및 기능 구현 #164
Changes from 6 commits
7e56c5d
0102f9e
22986b2
69c865b
587c984
9219c82
224e75e
d0b5207
e61dced
b4f6a34
58f4589
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 size를 인수로 받아 개수를 자유롭게 설정할 수 있군요👍🏻👍🏻 |
||
<div | ||
key={index} | ||
className="my-1 h-24 w-full animate-pulse rounded-2xl bg-dark-gray" | ||
></div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ResultListFallback; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useCallback, useEffect, useRef, useState } from 'react'; | ||
|
||
interface ObserverOptions { | ||
root?: Element | null; | ||
rootMargin?: string; | ||
threshold?: number; | ||
onObserve: VoidFunction; | ||
} | ||
|
||
const useIntersectionObserver = ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오.. IntersectionObserver API를 쉽게 활용할 수 있게 hooks로 만들어주셨군요! 👍👍 |
||
onObserve, | ||
...options | ||
}: ObserverOptions) => { | ||
const [isIntersecting, setIntersecting] = useState(false); | ||
const intersectionRef = useRef<HTMLDivElement>(null); | ||
|
||
const handleIntersect: IntersectionObserverCallback = useCallback( | ||
(entries, observer) => { | ||
entries.forEach((entry) => { | ||
if (entry.isIntersecting) { | ||
setIntersecting(true); | ||
onObserve(); | ||
observer.unobserve(entry.target); | ||
} else { | ||
setIntersecting(false); | ||
} | ||
}); | ||
}, | ||
[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, isIntersecting] as const; | ||
}; | ||
|
||
export default useIntersectionObserver; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as useInfiniteSearch } from './useInfiniteSearch'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useSuspenseInfiniteQuery } from '@tanstack/react-query'; | ||
import { RoomSelectType } from '@/core/types'; | ||
import roomAPI from '../functions/roomAPI'; | ||
|
||
const useInfiniteSearch = ({ | ||
type, | ||
size | ||
}: { | ||
type: RoomSelectType; | ||
size: number; | ||
}) => { | ||
const { fetchNextPage, hasNextPage, data, isFetchingNextPage } = | ||
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 | ||
}); | ||
|
||
return { | ||
fetchNextPage, | ||
hasNextPage, | ||
results: data, | ||
isFetchingNextPage | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 크게 생각하고 작성한 내용은 아닙니다만 허허 ,,! 그치만 어차피 컴포넌트 내에서 필요한 친구들만 빼서 쓰기 때문에 무관할 것 같네용 data 도 사실 data.map => rooms.map 을 하는게 보기 어려울 것 같아서 네이밍을 바꿔치기 한 것이었는데, |
||
}; | ||
|
||
export default useInfiniteSearch; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다 추후에 hasNextPage 속성을 이용해서 방이 더 이상 없다는 문구도 표시해주면 더 좋을 것 같습니다 ㄷㄷ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하 그렇네유 ! 문구 추천 부탁드립니다 꾸벅 ( _ _ )
더 이상 방이 없네요! 이거 .. ?