Skip to content

Commit 8d2d69a

Browse files
committed
feat(memory):
- remove unused comment count fetching logic and associated hook - add commentsCount in MemoryResponse
1 parent 18703be commit 8d2d69a

5 files changed

Lines changed: 4 additions & 90 deletions

File tree

src/components/MemoriesPage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ const MemoriesPage: React.FC<MemoriesPageProps> = ({ title, memoryType, requireA
8484
name: memory.member.nickname || memory.member.name,
8585
profileImage: memory.member.profile?.fileUrl || ''
8686
}}
87-
comments={memory.commentsCount || 0} // API에서 댓글 수 사용
88-
enableCommentsCount={!memory.commentsCount} // API에 commentsCount가 없으면 실시간 조회
87+
comments={memory.commentsCount || 0} // API에서 댓글 수 직접 제공
8988
/>
9089
))}
9190
</VStack>

src/components/MemoryCard.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { useState } from 'react';
22
import { Box, Image, Text, Flex, IconButton, Link, HStack, Avatar, Button } from '@chakra-ui/react';
33
import { useNavigate } from 'react-router-dom';
44
import { ViewIcon, ChatIcon } from '@chakra-ui/icons';
5-
import useMemoryCommentsCount from '../hooks/useMemoryCommentsCount';
65

76
interface Author {
87
id: number;
@@ -17,7 +16,6 @@ interface MemoryCardProps {
1716
author: Author;
1817
comments: number;
1918
source?: string; // sharing memories에서 온 경우 'sharing'
20-
enableCommentsCount?: boolean; // 댓글 수 조회 활성화 여부
2119
}
2220

2321
const MemoryCard: React.FC<MemoryCardProps> = ({
@@ -26,21 +24,11 @@ const MemoryCard: React.FC<MemoryCardProps> = ({
2624
description,
2725
author,
2826
comments,
29-
source,
30-
enableCommentsCount = false
27+
source
3128
}) => {
3229
const navigate = useNavigate();
3330
const [currentImageIndex, setCurrentImageIndex] = useState(0);
3431
const [isTextExpanded, setIsTextExpanded] = useState(false);
35-
36-
// 댓글 수 조회 (활성화된 경우만)
37-
const { commentsCount: fetchedCommentsCount } = useMemoryCommentsCount({
38-
memoryId,
39-
enabled: enableCommentsCount
40-
});
41-
42-
// enableCommentsCount가 true면 조회된 댓글 수 사용, 아니면 props로 받은 댓글 수 사용
43-
const displayCommentsCount = enableCommentsCount ? fetchedCommentsCount : comments;
4432

4533
const handleViewDetail = () => {
4634
// source가 있으면 query parameter로 전달
@@ -180,7 +168,7 @@ const MemoryCard: React.FC<MemoryCardProps> = ({
180168
onClick={handleViewDetail}
181169
_hover={{ bg: 'gray.50' }}
182170
>
183-
댓글 {displayCommentsCount}
171+
댓글 {comments}
184172
</Button>
185173
</HStack>
186174
</Box>

src/components/PublicMemoriesPage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ const PublicMemoriesPage: React.FC<PublicMemoriesPageProps> = ({ title, requireA
8282
name: memory.member.nickname || memory.member.name,
8383
profileImage: memory.member.profile?.fileUrl || ''
8484
}}
85-
comments={memory.commentsCount || 0} // API에서 댓글 수 사용
86-
enableCommentsCount={!memory.commentsCount} // API에 commentsCount가 없으면 실시간 조회
85+
comments={memory.commentsCount || 0} // API에서 댓글 수 직접 제공
8786
source="sharing" // sharing memories에서 온 경우
8887
/>
8988
))}

src/hooks/useCommentService.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,9 @@ const useCommentService = () => {
8282
}
8383
};
8484

85-
// 댓글 수만 조회 (가벼운 API) - 로그인 상태에 따라 다른 API 사용
86-
const getCommentsCount = async (memoryId: number): Promise<number> => {
87-
try {
88-
// 로그인 상태에 따라 API 엔드포인트 결정
89-
const endpoint = currentUser
90-
? `/v1/comments/memory/${memoryId}/top-level?page=0&size=1`
91-
: `/v1/comments/memory/public/${memoryId}/top-level?page=0&size=1`;
92-
93-
const response = await get<CommentsResponse>(endpoint);
94-
95-
if (response.data.statusCode === 200) {
96-
return response.data.data.totalCount;
97-
}
98-
99-
return 0;
100-
} catch (error: any) {
101-
console.error('댓글 수 조회 실패:', error);
102-
return 0;
103-
}
104-
};
105-
10685
return {
10786
getComments,
10887
createComment,
109-
getCommentsCount,
11088
loading,
11189
};
11290
};

src/hooks/useMemoryCommentsCount.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)