Skip to content

Commit 0f52000

Browse files
committed
[feat] lastLikeCount, lastCommentCount, 추가
1 parent 93eea3e commit 0f52000

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/domains/community/api/fetchPost.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export const fetchPostByTab = async ({
4343
category?: string;
4444
filter?: 'LATEST' | 'POPULAR' | 'COMMENTS';
4545
lastId?: number;
46-
lastLikeCount?: number;
47-
lastCommentCount?: number;
46+
lastLikeCount?: number | null;
47+
lastCommentCount?: number | null;
4848
}): Promise<Post[] | null> => {
4949
try {
5050
const params = new URLSearchParams();

src/domains/community/main/Community.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ function Community() {
3939
setIsLoading(true);
4040
setIsEnd(false);
4141

42-
// const latestPost = posts?.sort((a, b) => Number(b.createdAt) - Number(a.createdAt))
43-
// const latestLike = latestPost?.sort((a,b) => b.likeCount - a.likeCount );
44-
// const latestComment = latestPost?.sort((a,b) => b.commentCount - a.commentCount );
42+
const lastLikeCount =
43+
posts && posts.length > 0 ? Math.min(...posts.map((post) => post.likeCount)) : null;
44+
45+
const lastCommentCount =
46+
posts && posts.length > 0 ? Math.min(...posts.map((post) => post.commentCount)) : null;
4547

4648
try {
4749
const newPosts = await fetchPostByTab({
4850
category,
4951
filter,
52+
lastLikeCount,
53+
lastCommentCount,
5054
});
5155

5256
if (!newPosts || newPosts.length === 0) {

src/domains/community/main/CommunityFilter.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ function CommunityFilter({ posts, setPosts }: Props) {
2222
const query = searchParams.get('category');
2323
const router = useRouter();
2424

25-
const currentCategory = searchParams.get(query as string) || 'all';
26-
2725
useEffect(() => {
2826
console.log(query);
2927
}, [query]);

0 commit comments

Comments
 (0)