[network] #111 댓글 생성/목록 조회/수정/삭제 API 연동 - #112
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough댓글 처리를 목업 중심에서 실제 API 연동 방식으로 확장했습니다. 댓글 응답 매핑과 트리 변환, 페이징 조회, 생성·수정·삭제 API 처리를 추가했으며 편집된 댓글에는 수정 표시를 렌더링합니다. Changes댓글 API 및 표시 흐름
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CommentContent
participant useComments
participant api
CommentContent->>useComments: 댓글 조회 또는 변경 요청
useComments->>api: 댓글 API 호출
api-->>useComments: 댓글 응답 반환
useComments-->>CommentContent: 트리 구조와 isEdited 상태 제공
CommentContent-->>CommentContent: 편집 표시 렌더링
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/features/post/api/useComments.js (1)
80-175: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win댓글 작성/수정/삭제 시 로딩(제출 중) 상태 처리가 빠져있어요
addComment,addReply,updateComment,deleteComment모두 API 호출은 하지만, 진행 중임을 나타내는 상태(isSubmitting같은)가 전혀 없어요. 에러는setError로 잡고 있는데 반해 로딩 처리가 빠져 있는 게 아쉬워요. 이러면 사용자가 버튼을 연타했을 때 같은 요청이 중복으로 나가서 댓글이 두 번 생성되거나 삭제 요청이 중복으로 갈 수 있어요.작은
isSubmittingstate 하나 추가해서 요청 중엔 버튼을 비활성화하도록 컴포넌트에 노출해주면 좋을 것 같아요.🚦 addComment 기준 적용 예시 (다른 3개 함수도 동일 패턴)
+ const [isSubmitting, setIsSubmitting] = useState(false); + const addComment = async (newComment) => { if (USE_MOCK) { setComments((prev) => [...prev, { ...newComment, replies: [] }]); return; } + setIsSubmitting(true); try { const data = await api.post(ENDPOINTS.posts.comments(postId), { content: newComment.content, parentId: null, isPrivate: newComment.isPrivate ?? false, }); setComments((prev) => [...prev, { ...mapComment(data), replies: [] }]); } catch (e) { setError(e); + } finally { + setIsSubmitting(false); } };As per path instructions for
src/features/**/api/**, "로딩/에러 상태 처리가 누락되지 않았는지 확인하고" — 위 함수들의 로딩 상태 누락을 짚었어요.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/features/post/api/useComments.js` around lines 80 - 175, 댓글 mutation 흐름에 제출 중 상태를 추가하고 외부에 노출하세요. `addComment`, `addReply`, `updateComment`, `deleteComment` 각각의 API 요청 시작 전에 `isSubmitting`을 true로 설정하고, 성공·실패와 mock 경로를 포함해 항상 false로 복원되도록 처리해 중복 요청을 막으세요. 컴포넌트가 버튼을 비활성화할 수 있도록 해당 상태를 hook 반환값에 포함하세요.Source: Path instructions
🧹 Nitpick comments (1)
src/features/post/api/useComments.js (1)
80-175: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win반복되는 try/catch 패턴, 작은 헬퍼로 묶어도 좋을 것 같아요
addComment,addReply,updateComment,deleteComment가 전부try { ...api 호출... } catch (e) { setError(e) }구조를 그대로 반복하고 있어요. 필수는 아니지만, 공통 헬퍼로 뽑으면 나중에 로딩 상태나 재시도 로직을 추가할 때 한 곳만 고치면 돼서 유지보수가 편해져요.+ const runApiCall = async (fn) => { + try { + return await fn(); + } catch (e) { + setError(e); + return undefined; + } + };위처럼 만들어두고 각 함수에서
const data = await runApiCall(() => api.post(...))형태로 감싸면 중복이 줄어들어요.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/features/post/api/useComments.js` around lines 80 - 175, Extract the repeated API try/catch handling into a shared runApiCall helper that executes a request and calls setError on failure. Update addComment, addReply, updateComment, and deleteComment to use this helper while preserving their existing request payloads and state updates.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/features/post/api/useComments.js`:
- Around line 151-152: Update the comment-edit flow around findComment so the
!current case records an error through setError before returning. Preserve the
existing early return, and use the established error-state format or message
convention in this hook.
- Around line 55-67: Update the pagination loop in the comments-loading flow
around hasNext and idAfter to prevent unbounded requests. Add a maximum
iteration guard and stop when hasNext remains true without a valid advancing
nextIdAfter, while preserving normal pagination until the server signals
completion.
- Around line 14-27: Update mapComment to read the response fields raw.isDeleted
and raw.isEdited instead of raw.deleted and raw.edited, while preserving the
existing false defaults for missing values.
---
Outside diff comments:
In `@src/features/post/api/useComments.js`:
- Around line 80-175: 댓글 mutation 흐름에 제출 중 상태를 추가하고 외부에 노출하세요. `addComment`,
`addReply`, `updateComment`, `deleteComment` 각각의 API 요청 시작 전에 `isSubmitting`을
true로 설정하고, 성공·실패와 mock 경로를 포함해 항상 false로 복원되도록 처리해 중복 요청을 막으세요. 컴포넌트가 버튼을 비활성화할
수 있도록 해당 상태를 hook 반환값에 포함하세요.
---
Nitpick comments:
In `@src/features/post/api/useComments.js`:
- Around line 80-175: Extract the repeated API try/catch handling into a shared
runApiCall helper that executes a request and calls setError on failure. Update
addComment, addReply, updateComment, and deleteComment to use this helper while
preserving their existing request payloads and state updates.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 4f508071-0904-4b3f-8146-bc7b66762485
📒 Files selected for processing (3)
src/features/post/api/useComments.jssrc/features/post/components/CommentContent.jsxsrc/mocks/mockComments.js
☘️ 작업한 이슈
🍀 작업한 내용
🍃 작업 포인트
useComments훅 안에서VITE_USE_MOCK분기로 처리해, 댓글 UI 컴포넌트(CommentItem 등)는 수정 없이 그대로 동작합니다. 목업 모드 동작도 기존과 동일합니다.Summary by CodeRabbit
(수정됨)으로 구분해 표시합니다.