diff --git a/frontend/src/pages/Bucket/BucketDetail/Comment/Comment.tsx b/frontend/src/pages/Bucket/BucketDetail/Comment/Comment.tsx index ce1f523d..459f45b8 100644 --- a/frontend/src/pages/Bucket/BucketDetail/Comment/Comment.tsx +++ b/frontend/src/pages/Bucket/BucketDetail/Comment/Comment.tsx @@ -1,8 +1,10 @@ +import { ChangeEvent, MouseEvent, useState } from 'react' import UserProfile from '../../../../components/UserProfile' import { ICommentItem, TimeUnitType } from '../../../../interfaces' import ActiveLikeButton from './ActiveLikeButton' import ShowMoreButton from './ShowMoreButton' import UnActiveLikeButton from './UnActiveLikeButton' +import { useDetailPageTypeStore } from '../../../../store/detailStore' const getTime = (time: number, timeUnit: TimeUnitType): string => { switch (timeUnit) { @@ -23,15 +25,56 @@ const getTime = (time: number, timeUnit: TimeUnitType): string => { interface ICommentProps { commentInfo: ICommentItem + type: 'read' | 'edit' + setSelectedId: React.Dispatch> } -const Comment = ({ commentInfo }: ICommentProps) => { +const Comment = ({ commentInfo, type, setSelectedId }: ICommentProps) => { + const { setPageType } = useDetailPageTypeStore() + const [editText, setEditText] = useState('') + + // handler about Comment + // Todo: handleChangeCommit으로 함수명 변경, edit 관련 함수가 너무 많아서 이름을 명시적으로 변경 + const handleEditComment = (event: ChangeEvent) => { + const inputText = event.currentTarget.value + setEditText(inputText) + } + // 이벤트 버블링을 이용한 이벤트 동작 수행 + const handleClickComment = (event: MouseEvent) => { + const { id } = event.currentTarget.dataset + id && setSelectedId(parseInt(id)) + } + + // handler about ShowMoreButton + const handleCancelEdit = () => { + setEditText('') + setPageType('read') + } + const handleCompleteEdit = () => { + // Todo: 댓글 수정 Api 적용 예정 + setPageType('read') + } return ( -
+
{/* //Todo: comment 유저로 정보 변경 필요 */}

{getTime(commentInfo.time, commentInfo.timeUnit)}

-

{commentInfo.context}

+ {type === 'read' ? ( +

{commentInfo.context}

+ ) : ( +
+