@@ -6,6 +6,8 @@ import { useInfiniteScrollObserver } from '@/shared/hook/useInfiniteScrollObserv
66import { useItemVirtualizer } from '@/domains/community/hook/useItemVirtualizer' ;
77import { useCommentEnterAnimation } from '@/domains/community/hook/useCommentAnimation' ;
88import { usePrevious } from 'react-use' ;
9+ import Link from 'next/link' ;
10+ import { getApi } from '@/app/api/config/appConfig' ;
911
1012type Props = {
1113 comments : CommentType [ ] | null ;
@@ -27,7 +29,6 @@ function CommentList({
2729 isEnd,
2830 myPage = false ,
2931} : Props ) {
30-
3132 const parentRef = useRef < HTMLDivElement | null > ( null ) ;
3233 const [ editCommentId , setEditCommentId ] = useState < number | null > ( null ) ;
3334 const [ editedContentMap , setEditedContentMap ] = useState < Record < number , string > > ( { } ) ;
@@ -71,12 +72,100 @@ function CommentList({
7172 >
7273 < ul style = { { height : rowVirtualizer . getTotalSize ( ) , position : 'relative' } } >
7374 { rowVirtualizer . getVirtualItems ( ) . map ( ( { index, key, start } ) => {
74- const { commentId, content, userNickName, createdAt } = comments [ index ] ;
75+ const { commentId, content, userNickName, createdAt, postId } = comments [ index ] ;
7576 const isEditing = editCommentId === commentId ;
7677 const isMyComment = comments && currentUserNickname === userNickName ;
7778 const isLast = index === comments . length - 1 ;
7879
79- return (
80+ return myPage ? (
81+ < Link href = { `/community/${ postId } ` } key = { key } >
82+ < li
83+ className = "border-b-1 border-gray py-3"
84+ data-index = { index }
85+ ref = { ( el ) => {
86+ if ( el ) {
87+ requestAnimationFrame ( ( ) => {
88+ try {
89+ rowVirtualizer . measureElement ( el ) ;
90+ } catch ( e ) {
91+ console . error ( 'measureElement failed' , e ) ;
92+ }
93+ } ) ;
94+ if ( index === 0 ) firstItemRef . current = el ;
95+ if ( isLast ) observeLastItem ( el ) ;
96+ }
97+ } }
98+ style = { {
99+ position : 'absolute' ,
100+ top : 0 ,
101+ left : 0 ,
102+ width : '100%' ,
103+ transform : `translateY(${ start } px)` ,
104+ minHeight : '60px' , // ← 최소 보장
105+ } }
106+ >
107+ < article >
108+ < CommentTitle
109+ userNickname = { myPage ? currentUserNickname ! : userNickName }
110+ commentTime = { createdAt }
111+ isMyComment = { isMyComment }
112+ isEditing = { isEditing }
113+ myPage = { myPage }
114+ onSubmitEdit = { ( ) => {
115+ const updatedContent = editedContentMap [ commentId ] ;
116+ if ( ! updatedContent ) return ;
117+ if ( ! onUpdateComment ) return ;
118+ onUpdateComment ( commentId , updatedContent ) . then ( ( ) => {
119+ setEditCommentId ( null ) ;
120+ setEditedContentMap ( ( prev ) => {
121+ const next = { ...prev } ;
122+ delete next [ commentId ] ;
123+ return next ;
124+ } ) ;
125+ } ) ;
126+ } }
127+ onDelete = { ( ) => {
128+ if ( ! onDeleteComment ) return ;
129+ onDeleteComment ( commentId ) ;
130+ } }
131+ onEdit = { ( ) => {
132+ setEditCommentId ( commentId ) ;
133+ setEditedContentMap ( ( prev ) => ( {
134+ ...prev ,
135+ [ commentId ] : content , // 기존 내용 세팅
136+ } ) ) ;
137+ } }
138+ onCancelEdit = { ( ) => {
139+ setEditCommentId ( null ) ;
140+ setEditedContentMap ( ( prev ) => {
141+ const next = { ...prev } ;
142+ delete next [ commentId ] ;
143+ return next ;
144+ } ) ;
145+ } }
146+ />
147+ < article className = "mt-4 h-full" >
148+ { isEditing ? (
149+ < AutoGrowingTextarea
150+ value = { editedContentMap [ commentId ] ?? content }
151+ rowVirtualize = { rowVirtualizer }
152+ onChange = { ( e ) =>
153+ setEditedContentMap ( ( prev ) => ( {
154+ ...prev ,
155+ [ commentId ] : e . target . value ,
156+ } ) )
157+ }
158+ />
159+ ) : (
160+ < div className = "mt-4" >
161+ < p className = "whitespace-pre-wrap" > { content } </ p >
162+ </ div >
163+ ) }
164+ </ article >
165+ </ article >
166+ </ li >
167+ </ Link >
168+ ) : (
80169 < li
81170 className = "border-b-1 border-gray py-3"
82171 key = { key }
@@ -105,15 +194,15 @@ function CommentList({
105194 >
106195 < article >
107196 < CommentTitle
108- userNickname = { myPage ? currentUserNickname ! : userNickName }
197+ userNickname = { myPage ? currentUserNickname ! : userNickName }
109198 commentTime = { createdAt }
110199 isMyComment = { isMyComment }
111200 isEditing = { isEditing }
112201 myPage = { myPage }
113202 onSubmitEdit = { ( ) => {
114203 const updatedContent = editedContentMap [ commentId ] ;
115204 if ( ! updatedContent ) return ;
116- if ( ! onUpdateComment ) return
205+ if ( ! onUpdateComment ) return ;
117206 onUpdateComment ( commentId , updatedContent ) . then ( ( ) => {
118207 setEditCommentId ( null ) ;
119208 setEditedContentMap ( ( prev ) => {
@@ -123,10 +212,9 @@ function CommentList({
123212 } ) ;
124213 } ) ;
125214 } }
126-
127215 onDelete = { ( ) => {
128- if ( ! onDeleteComment ) return
129- onDeleteComment ( commentId )
216+ if ( ! onDeleteComment ) return ;
217+ onDeleteComment ( commentId ) ;
130218 } }
131219 onEdit = { ( ) => {
132220 setEditCommentId ( commentId ) ;
0 commit comments