diff --git a/src/app/(MainLayout)/components/FeedComment/FeedComment.tsx b/src/app/(MainLayout)/components/FeedComment/FeedComment.tsx index 710eae8..333bf65 100644 --- a/src/app/(MainLayout)/components/FeedComment/FeedComment.tsx +++ b/src/app/(MainLayout)/components/FeedComment/FeedComment.tsx @@ -1,9 +1,11 @@ import Image from 'next/image'; import { compactTimeFormatter, digitNumberFormatter } from '@/utils/formatter'; +import ToggleWrapper from '@/components/common/ToggleWrapper'; +import LikeButton from '../LikeButton'; +import FeedReplyWriteInput from '../FeedReplyWriteInput'; import styles from './FeedComment.module.scss'; -import LikeButton from '../LikeButton'; export type FeedCommentType = { commentId: string; @@ -22,7 +24,7 @@ interface FeedCommentProps { const FeedComment = ({ commentData }: FeedCommentProps) => { const { - // commentId, + commentId, nickname, profileUrl, feedContent, @@ -47,11 +49,23 @@ const FeedComment = ({ commentData }: FeedCommentProps) => {

{feedContent}

-
- {compactTimeFormatter(updatedAt ?? createdAt)} - 좋아요 {digitNumberFormatter(likeCount)}개 - 답글 달기 -
+ + {({ isToggle, toggleHandler }) => ( + <> +
+ {compactTimeFormatter(updatedAt ?? createdAt)} + 좋아요 {digitNumberFormatter(likeCount)}개 + +
+ {isToggle && } + + )} +
); }; diff --git a/src/app/(MainLayout)/components/FeedCommentList/FeedCommentList.module.scss b/src/app/(MainLayout)/components/FeedCommentList/FeedCommentList.module.scss index 87ce7f4..81fb65c 100644 --- a/src/app/(MainLayout)/components/FeedCommentList/FeedCommentList.module.scss +++ b/src/app/(MainLayout)/components/FeedCommentList/FeedCommentList.module.scss @@ -1,14 +1,17 @@ @use '../../../../styles/helpers/index' as *; .container { - height: 100%; + flex: 1; + display: flex; + flex-direction: column; +} + +.comment_container { padding: 1.25rem; - overflow: scroll; } -.container_non_padding { +.reply_container { padding-left: 2rem; - overflow: scroll; } .reply_comment { diff --git a/src/app/(MainLayout)/components/FeedCommentList/FeedCommentList.tsx b/src/app/(MainLayout)/components/FeedCommentList/FeedCommentList.tsx index 0554065..ea3226e 100644 --- a/src/app/(MainLayout)/components/FeedCommentList/FeedCommentList.tsx +++ b/src/app/(MainLayout)/components/FeedCommentList/FeedCommentList.tsx @@ -1,6 +1,7 @@ 'use client'; -import { useEffect, useState } from 'react'; +import clsx from 'clsx'; +import { Fragment, useEffect, useState } from 'react'; import If from '@/components/common/If'; import ToggleWrapper from '@/components/common/ToggleWrapper'; @@ -8,25 +9,25 @@ import FeedComment, { FeedCommentType } from '../FeedComment/FeedComment'; import styles from './FeedCommentList.module.scss'; -const asyncMockDataResponse = async () => { - let uniqueId = 1; +const makeMockData = (id: number) => ({ + // eslint-disable-next-line no-plusplus + commentId: Math.ceil(Math.random() * 6), + nickname: `홍길동${id + 1}`, + profileUrl: + 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT4vkwPhD-NHO6sV_3ailgWXjiP_WPM24J3IhkB3xZ-bQ&s', + feedContent: + '내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 \n내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력', + createdAt: '2024-10-25 20:08:22', + updatedAt: '2024-10-28 21:29:22', + likeCount: 1357345 + id, + childFeedComments: +id < 4 ? [4, 5, 6] : [], +}); + +const asyncMockDataResponse = () => { return async (id: string) => { - if (uniqueId < 4) { + if (+id < 7) { return new Promise((res) => { - const data = { - // eslint-disable-next-line no-plusplus - commentId: (uniqueId++).toString(), - nickname: `홍길동${id + 1}`, - profileUrl: - 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT4vkwPhD-NHO6sV_3ailgWXjiP_WPM24J3IhkB3xZ-bQ&s', - feedContent: - '내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 \n내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력 내용 입력', - createdAt: '2024-10-25 20:08:22', - updatedAt: '2024-10-28 21:29:22', - likeCount: 1357345 + id, - childFeedComments: +id < 4 ? [4, 5, 6] : [], - }; - + const data = makeMockData(+id); res(data); }); } @@ -37,61 +38,72 @@ const asyncMockDataResponse = async () => { interface FeedCommentListProps { feedId?: string; + commentId?: string; feedCommentIds: string[]; } -const FeedCommentList = ({ feedId, feedCommentIds }: FeedCommentListProps) => { +const FeedCommentList = ({ + feedId, + commentId, + feedCommentIds, +}: FeedCommentListProps) => { const [commentData, setCommentData] = useState([]); useEffect(() => { (async function () { - const result = (await Promise.all( - feedCommentIds.map(await asyncMockDataResponse()), - )) as FeedCommentType[]; + const requests = await feedCommentIds.map(await asyncMockDataResponse()); + const result = (await Promise.all(requests)) as FeedCommentType[]; setCommentData(result); })(); }, []); return ( -
- - {commentData.map((feedComment) => ( - <> - +
+ + + {commentData.map((comment) => ( + + - - - - {({ isToggle, toggleHandler }) => ( - <> - {!isToggle && ( -
-
- -
- )} + + + + {({ isToggle, toggleHandler }) => ( + <> + {!isToggle && ( +
+
+ +
+ )} - {isToggle && ( - - )} - - )} - - - - - ))} + {isToggle && ( + + )} + + )} + + + + + ))} +
); diff --git a/src/app/(MainLayout)/components/FeedCommentWriteInput/FeedCommentWriteInput.tsx b/src/app/(MainLayout)/components/FeedCommentWriteInput/FeedCommentWriteInput.tsx index 350e84d..cfb7e02 100644 --- a/src/app/(MainLayout)/components/FeedCommentWriteInput/FeedCommentWriteInput.tsx +++ b/src/app/(MainLayout)/components/FeedCommentWriteInput/FeedCommentWriteInput.tsx @@ -19,20 +19,20 @@ const FeedCommentWriteInput = ({ parentId, placeholder = '댓글 달기...', }: FeedCommentWriteInputProps) => { - const { commentContent, setCommentContent, textareaRef } = + const { textareaContent, setTextareaContent, textareaRef } = useAutoResizeTextArea({ maxLine: 3, lineHeight: 20 }); const changeHandler = (e: ChangeEvent) => { const { value } = e.target; if (value.length <= MAX_LENGTH) { - setCommentContent(value); + setTextareaContent(value); } }; const submitHandler = () => { console.log(postId, parentId); - if (commentContent) { - console.log('게시'); + if (textareaContent) { + console.log(textareaContent); } }; @@ -42,7 +42,7 @@ const FeedCommentWriteInput = ({ className={styles.comment_textarea} placeholder={placeholder} onChange={changeHandler} - value={commentContent} + value={textareaContent} ref={textareaRef} />