Skip to content

Commit

Permalink
refactor: 더보기 로직 변경 (#267)
Browse files Browse the repository at this point in the history
- 더보기 로직 변경
  • Loading branch information
ysh4296 authored Dec 3, 2023
1 parent 5fc1677 commit b2746f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/screens/detailedPost/CommentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ const CommentList = ({ insightId, authorId, handleReplyClick, commentList }: Com
onReply={() => handleReplyClick({ id: item.id, nickname: item.writer?.name ?? '' })}
commentId={item.id}
/>
<ReplyList insightId={insightId} parentId={item.id} authorId={authorId} />
<ReplyList
insightId={insightId}
parentId={item.id}
authorId={authorId}
totalReply={item.totalReply ?? 0}
/>
</>
))}
</>
Expand Down
13 changes: 9 additions & 4 deletions src/screens/detailedPost/ReplyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { Pressable, View, Text } from 'react-native';
import { SvgXml } from 'react-native-svg';
import CommentXml from '../../constants/Icons/Comment/CommentXml';

const REPLY_LIMIT = 10;
const REPLY_LIMIT = 5;

interface ReplyListProps {
insightId: number;
parentId: number;
authorId: number;
totalReply: number;
}

const ReplyList = ({ insightId, parentId, authorId }: ReplyListProps) => {
const { data, fetchNextPage, hasNextPage } = useInfiniteQuery({
const ReplyList = ({ insightId, parentId, authorId, totalReply }: ReplyListProps) => {
const { data, fetchNextPage } = useInfiniteQuery({
queryKey: InsightQueryKeys.getReplies({
insightId,
parentId,
Expand All @@ -28,6 +29,10 @@ const ReplyList = ({ insightId, parentId, authorId }: ReplyListProps) => {
},
});

const totalCount = data?.pages.reduce((accumulator, currentArray) => {
return accumulator + (currentArray?.length ?? 0);
}, 0);

return (
<View style={{ marginLeft: 8 }}>
{data?.pages?.flatMap((page) =>
Expand All @@ -46,7 +51,7 @@ const ReplyList = ({ insightId, parentId, authorId }: ReplyListProps) => {
/>
)),
)}
{hasNextPage && (
{totalCount !== totalReply && (
<Pressable
style={{ marginLeft: 100, flexDirection: 'row', alignItems: 'center' }}
onPress={() => fetchNextPage()}
Expand Down

0 comments on commit b2746f5

Please sign in to comment.