forked from SWYP-team-2th/client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
댓글 페이지네이션을 구현한다. (SWYP-team-2th#143)
* 댓글 페이지네이션을 구현한다. * 파일 분리 * 로딩 처리
- Loading branch information
Showing
15 changed files
with
177 additions
and
97 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
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,29 @@ | ||
import useCommentDetail from '../hooks'; | ||
import Loading from '@/components/common/Loading'; | ||
import CommentItem from '@/components/vote-detail/Comment/CommentItems'; | ||
|
||
export default function CommentList() { | ||
const { comments, observerRef, isLoading } = useCommentDetail(); | ||
|
||
return ( | ||
<div className="h-full overflow-y-auto"> | ||
{isLoading ? ( | ||
<Loading /> | ||
) : ( | ||
<> | ||
<div className="text-title-large mt-lg pl-sm pb-[9px]"> | ||
한마디 ({comments?.length}) | ||
</div> | ||
<hr className="text-gray-300 mb-[20px]" /> | ||
|
||
<div> | ||
{comments?.map((comment) => ( | ||
<CommentItem key={comment.commentId} comment={comment} /> | ||
))} | ||
<div ref={observerRef} style={{ height: '10px' }} /> | ||
</div> | ||
</> | ||
)} | ||
</div> | ||
); | ||
} |
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 } from './CommentList'; |
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,44 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import useComment from '../vote-detail/Comment/CommentList/hooks'; | ||
|
||
export default function useCommentDetail() { | ||
const { | ||
commentsData, | ||
hasNextPage, | ||
isLoading, | ||
isFetchingNextPage, | ||
fetchNextPage, | ||
} = useComment(20); | ||
|
||
const comments = commentsData?.pages.flatMap((page) => page.data); | ||
|
||
const observerRef = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
const observer = new IntersectionObserver( | ||
(entries) => { | ||
if (entries[0].isIntersecting && hasNextPage && !isFetchingNextPage) { | ||
fetchNextPage(); | ||
} | ||
}, | ||
{ threshold: 0.1 }, | ||
); | ||
|
||
const currentObserver = observerRef.current; | ||
if (currentObserver) { | ||
observer.observe(currentObserver); | ||
} | ||
|
||
return () => { | ||
if (currentObserver) { | ||
observer.unobserve(currentObserver); | ||
} | ||
}; | ||
}, [hasNextPage, fetchNextPage, isFetchingNextPage]); | ||
|
||
return { | ||
comments, | ||
observerRef, | ||
isLoading, | ||
}; | ||
} |
65 changes: 36 additions & 29 deletions
65
src/components/vote-detail/Comment/CommentList/CommentList.tsx
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
9 changes: 0 additions & 9 deletions
9
src/components/vote-detail/Comment/CommentSection/CommentSection.tsx
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
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
Oops, something went wrong.