1+ import { CheckBox } from "@/components/common/CheckBox/CheckBox" ;
12import React , { useState } from "react" ;
23import classes from "./CommentBox.module.css" ;
3- import { CheckBox } from "@/components/common/CheckBox/CheckBox" ;
4-
54interface CommentBoxProps {
65 onSubmit ?: ( comment : string , isAnonymous : boolean ) => void ;
76 commentList ?: Comment [ ] ;
@@ -17,10 +16,6 @@ export const CommentBox: React.FC<CommentBoxProps> = ({ onSubmit, commentList =
1716 const [ comment , setComment ] = useState ( "" ) ;
1817 const [ isAnonymous , setIsAnonymous ] = useState < boolean > ( true ) ;
1918
20- // 익명 번호 매핑을 위한 Map 객체
21- const anonymousMap = new Map < string , number > ( ) ;
22- let anonymousCounter = 1 ;
23-
2419 const handleChange = ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
2520 setComment ( e . target . value ) ;
2621 } ;
@@ -59,29 +54,18 @@ export const CommentBox: React.FC<CommentBoxProps> = ({ onSubmit, commentList =
5954 </ div >
6055 < CheckBox
6156 label = "익명으로 작성"
62- checked = { true }
57+ checked = { isAnonymous }
6358 onChange = { ( status ) => setIsAnonymous ( status ) }
6459 />
6560 </ form >
6661 < div className = { classes . divider } > </ div >
6762 < div className = { classes . commentsList } >
6863 { commentList . map ( ( commentItem , index ) => {
69- let displayAuthor = commentItem . author ;
70-
71- if ( commentItem . isAnonymous ) {
72- // 익명 댓글일 경우
73- if ( ! anonymousMap . has ( commentItem . author ) ) {
74- // 익명 번호가 없는 경우 새 번호 부여
75- anonymousMap . set ( commentItem . author , anonymousCounter ++ ) ;
76- }
77- displayAuthor = `익명${ anonymousMap . get ( commentItem . author ) } ` ;
78- }
64+ // 익명이라면 "익명", 아니라면 author 표시
65+ const displayAuthor = commentItem . isAnonymous ? "익명" : commentItem . author ;
7966
8067 return (
8168 < div key = { index } className = { classes . commentItem } >
82- { /* <div className={classes.commentAuthor}>
83- {commentItem.isAnonymous ? `익명${anonymousIndex}` : commentItem.author}
84- </div> */ }
8569 < div className = { classes . commentAuthor } > { displayAuthor } </ div >
8670 < div className = { classes . commentContent } > { commentItem . content } </ div >
8771 </ div >
0 commit comments