))
)
- case '내가 쓴 댓글':
+ case `${profile?.teacherInfo.nickName} 쓴 댓글`:
return (
commentList &&
commentList.result.map((item: CommentI, index: number) => (
-
-
+
))
@@ -97,7 +106,7 @@ const MemberListCount = ({ id }: MemberListCountProps) => {
return (
- {TABS.map((tab) => (
+ {tabs.map((tab) => (
-
diff --git a/src/components/board/CommentList.tsx b/src/components/board/CommentList.tsx
index c31f105..fc978bd 100644
--- a/src/components/board/CommentList.tsx
+++ b/src/components/board/CommentList.tsx
@@ -1,7 +1,10 @@
'use client'
+import { useState } from 'react'
import { useCommentList } from '@/service/comment/useCommentService'
+import { CommentI } from '@/model/Comment'
import Comment from './Comment'
+import ChattingInput from '../chatting/ChattingInput'
interface CommentListProps {
id: number
@@ -10,12 +13,64 @@ interface CommentListProps {
}
const CommentList = ({ id, page, size }: CommentListProps) => {
+ const [newComment, setNewComment] = useState
(new FormData())
const { data: commentList } = useCommentList({ id, page, size })
+ const handleCommentChange = (e: React.ChangeEvent) => {
+ const formData = new FormData()
+ formData.append('comment', e.target.value)
+ setNewComment(formData)
+ }
+
+ const handleShareBtnClick = () => {
+ console.log('share')
+ }
+ const handleReportBtnClick = () => {
+ console.log('report')
+ }
+ const handleCommentSubmit = () => {
+ console.log('submit')
+ }
+
return (
-
+
+
+
+ 전체 댓글 {commentList && commentList.totalSize}개
+
+
+
+ 공유
+
+
+ 신고
+
+
+
+
{commentList &&
- commentList.result.map((comment) =>
)}
+ commentList.result.map((comment: CommentI) => (
+ <>
+
+
+ >
+ ))}
+
+
+
+
)
}
diff --git a/src/components/chatting/ChattingInput.tsx b/src/components/chatting/ChattingInput.tsx
index 630dff4..b2e9830 100644
--- a/src/components/chatting/ChattingInput.tsx
+++ b/src/components/chatting/ChattingInput.tsx
@@ -4,11 +4,17 @@ import Button from '../common/Button'
export interface ChattingInputProps {
value: string
+ placeholder?: string
onChange: (e: React.ChangeEvent
) => void
onClick: () => void
}
-const ChattingInput = ({ value, onChange, onClick }: ChattingInputProps) => {
+const ChattingInput = ({
+ value,
+ placeholder,
+ onChange,
+ onClick,
+}: ChattingInputProps) => {
const handleKeyPress = (e: React.KeyboardEvent) => {
if (e.key === 'Enter') {
onClick()
@@ -19,14 +25,19 @@ const ChattingInput = ({ value, onChange, onClick }: ChattingInputProps) => {
)
}
+ChattingInput.defaultProps = {
+ placeholder: '',
+}
+
export default ChattingInput
diff --git a/src/service/comment/CommentQueries.ts b/src/service/comment/CommentQueries.ts
index 225d732..9253052 100644
--- a/src/service/comment/CommentQueries.ts
+++ b/src/service/comment/CommentQueries.ts
@@ -5,40 +5,39 @@ import CommentService, {
} from './CommentService'
const queryKeys = {
- commentList: ['commentList'] as const,
- commentBest: ['commentBest'] as const,
- discussionCommentList: ['discussionCommentList'] as const,
- discussionCommentBest: ['discussionCommentBest'] as const,
+ commentList: (id: number) => ['commentList', id] as const,
+ commentBest: (id: number) => ['commentBest', id] as const,
+ discussionCommentList: (id: number) => ['discussionCommentList', id] as const,
+ discussionCommentBest: (id: number) => ['discussionCommentBest', id] as const,
}
const queryOptions = {
// 게시판 댓글
- commentList: {
- queryKey: queryKeys.commentList,
- queryFn: async ({ id, page, size }: CommentListProps) => {
+ commentList: (id: number) => ({
+ queryKey: queryKeys.commentList(id),
+ queryFn: async ({ page, size }: Omit) => {
const res = await CommentService.getCommentList({ id, page, size })
return res.data
},
- },
+ }),
- commentListMember: {
- queryKey: queryKeys.commentList,
- queryFn: async ({ id, page, size }: CommentListProps) => {
+ commentListMember: (id: number) => ({
+ queryKey: queryKeys.commentList(id),
+ queryFn: async ({ page, size }: Omit) => {
const res = await CommentService.getCommentListMember({ id, page, size })
return res.data
},
- },
+ }),
- commentBest: {
- queryKey: queryKeys.commentBest,
- queryFn: async ({ id, page, size }: CommentListProps) => {
+ commentBest: (id: number) => ({
+ queryKey: queryKeys.commentBest(id),
+ queryFn: async ({ page, size }: Omit) => {
const res = await CommentService.getCommentBest({ id, page, size })
return res.data
},
- },
+ }),
postCommentLike: {
- queryKey: queryKeys.commentList,
mutationFn: async ({
id,
commentId,
@@ -48,7 +47,6 @@ const queryOptions = {
},
postComment: {
- queryKey: queryKeys.commentList,
mutationFn: async ({
id,
comment,
@@ -63,7 +61,6 @@ const queryOptions = {
},
deleteComment: {
- queryKey: queryKeys.commentList,
mutationFn: async ({
id,
commentId,
@@ -73,9 +70,9 @@ const queryOptions = {
},
// 토론 게시판 댓글
- discussionCommentList: {
- queryKey: queryKeys.discussionCommentList,
- queryFn: async ({ id, page, size }: CommentListProps) => {
+ discussionCommentList: (id: number) => ({
+ queryKey: queryKeys.discussionCommentList(id),
+ queryFn: async ({ page, size }: Omit) => {
const res = await CommentService.getDiscussionCommentList({
id,
page,
@@ -83,11 +80,11 @@ const queryOptions = {
})
return res.data
},
- },
+ }),
- discussionCommentListMember: {
- queryKey: queryKeys.discussionCommentList,
- queryFn: async ({ id, page, size }: CommentListProps) => {
+ discussionCommentListMember: (id: number) => ({
+ queryKey: queryKeys.discussionCommentList(id),
+ queryFn: async ({ page, size }: Omit) => {
const res = await CommentService.getDiscussionCommentListMember({
id,
page,
@@ -95,11 +92,11 @@ const queryOptions = {
})
return res.data
},
- },
+ }),
- discussionCommentBest: {
- queryKey: queryKeys.discussionCommentBest,
- queryFn: async ({ id, page, size }: CommentListProps) => {
+ discussionCommentBest: (id: number) => ({
+ queryKey: queryKeys.discussionCommentBest(id),
+ queryFn: async ({ page, size }: Omit) => {
const res = await CommentService.getDiscussionCommentBest({
id,
page,
@@ -107,7 +104,7 @@ const queryOptions = {
})
return res.data
},
- },
+ }),
postDiscussionCommentLike: {
queryKey: queryKeys.discussionCommentList,
diff --git a/src/service/comment/useCommentService.ts b/src/service/comment/useCommentService.ts
index d003d41..a12c147 100644
--- a/src/service/comment/useCommentService.ts
+++ b/src/service/comment/useCommentService.ts
@@ -13,23 +13,20 @@ import {
// 게시판 댓글
const useCommentList = ({ id, page, size }: CommentListProps) =>
useQuery({
- ...queryOptions.commentList,
- queryKey: ['commentList'],
- queryFn: () => queryOptions.commentList.queryFn({ id, page, size }),
+ ...queryOptions.commentList(id),
+ queryFn: () => queryOptions.commentList(id).queryFn({ page, size }),
})
const useCommentListMember = (id: number, page: number, size: number) =>
useQuery({
- ...queryOptions.commentListMember,
- queryKey: ['commentListMember'],
- queryFn: () => queryOptions.commentListMember.queryFn({ id, page, size }),
+ ...queryOptions.commentListMember(id),
+ queryFn: () => queryOptions.commentListMember(id).queryFn({ page, size }),
})
const useCommentBest = ({ id, page, size }: CommentListProps) =>
useQuery({
- ...queryOptions.commentBest,
- queryKey: ['commentBest'],
- queryFn: () => queryOptions.commentBest.queryFn({ id, page, size }),
+ ...queryOptions.commentBest(id),
+ queryFn: () => queryOptions.commentBest(id).queryFn({ page, size }),
})
const useCommentLike = () => {
@@ -71,26 +68,23 @@ const useDeleteComment = () => {
// 토론 게시판 댓글
const useDiscussionCommentList = ({ id, page, size }: CommentListProps) =>
useQuery({
- ...queryOptions.discussionCommentList,
- queryKey: ['discussionCommentList'],
+ ...queryOptions.discussionCommentList(id),
queryFn: () =>
- queryOptions.discussionCommentList.queryFn({ id, page, size }),
+ queryOptions.discussionCommentList(id).queryFn({ page, size }),
})
const useDiscussionCommentListMember = ({ id, page, size }: CommentListProps) =>
useQuery({
- ...queryOptions.discussionCommentListMember,
- queryKey: ['discussionCommentListMember'],
+ ...queryOptions.discussionCommentListMember(id),
queryFn: () =>
- queryOptions.discussionCommentListMember.queryFn({ id, page, size }),
+ queryOptions.discussionCommentListMember(id).queryFn({ page, size }),
})
const useDiscussionCommentBest = ({ id, page, size }: CommentListProps) =>
useQuery({
- ...queryOptions.discussionCommentBest,
- queryKey: ['discussionCommentBest'],
+ ...queryOptions.discussionCommentBest(id),
queryFn: () =>
- queryOptions.discussionCommentBest.queryFn({ id, page, size }),
+ queryOptions.discussionCommentBest(id).queryFn({ page, size }),
})
const useDiscussionCommentLike = () => {