@@ -14,6 +14,9 @@ type Props = {
1414 posts : Post [ ] | null ;
1515 setPost ?: ( value : Post [ ] | null ) => void ;
1616 isLoading : boolean ;
17+ setIsLoading ?: ( value : boolean ) => void ;
18+ isEnd ?: boolean ;
19+ onLoadMore ?: ( lastPostId : number ) => Promise < void > ;
1720} ;
1821
1922function PostCard ( { posts, isLoading, isEnd, onLoadMore } : Props ) {
@@ -38,65 +41,81 @@ function PostCard({ posts, isLoading, isEnd, onLoadMore }: Props) {
3841
3942 return (
4043 < >
41- { posts . map (
42- ( {
43- postId,
44- categoryName,
45- title,
46- content,
47- userNickName,
48- viewCount,
49- createdAt,
50- commentCount,
51- imageUrl,
52- } ) => (
53- < article className = "py-4 sm:py-5 border-b-1 border-gray-light" key = { postId } >
54- < Label title = { categoryName } />
44+ { posts &&
45+ posts . map (
46+ (
47+ {
48+ postId,
49+ categoryName,
50+ title,
51+ content,
52+ userNickName,
53+ viewCount,
54+ createdAt,
55+ commentCount,
56+ imageUrls,
57+ } ,
58+ index
59+ ) => {
60+ const isLast = index === posts . length - 1 ;
61+ return (
62+ < article
63+ className = "py-4 sm:py-5 border-b-1 border-gray-light"
64+ key = { postId }
65+ ref = { ( el ) => {
66+ if ( index === 0 ) firstItemRef . current = el ;
67+ if ( isLast ) {
68+ observeLastItem ( el ) ;
69+ }
70+ } }
71+ >
72+ < Label title = { categoryName } />
5573
56- < section
57- onClick = { ( ) => handlePost ( postId ) }
58- className = "flex items-center gap-3 justify-between mt-3 cursor-pointer h-full"
59- role = "link"
60- >
61- < div className = "flex flex-col gap-3 md:max-w-[51.25rem] sm:max-w-[27.5rem] max-w-[19.375rem] flex-grow content-between h-full" >
62- < p className = "font-bold sm:text-xl text-lg" > { title } </ p >
63- < div className = "font-light sm:text-[15px] text-sm md:max-w-[820px] sm:max-w-[440px] max-w-[210px] h-full" >
64- < p
65- className = "h-10"
66- style = { {
67- display : '-webkit-box' ,
68- WebkitBoxOrient : 'vertical' ,
69- WebkitLineClamp : 2 ,
70- overflow : 'hidden' ,
71- textOverflow : 'ellipsis' ,
72- } }
73- >
74- { content }
75- </ p >
76- </ div >
77- < PostInfo
78- hasUserName = { true }
79- userNickName = { userNickName }
80- viewCount = { viewCount }
81- createdAt = { createdAt }
82- commentCount = { commentCount }
83- />
84- </ div >
85- < figure className = "flex items-center flex-shrink-0 md:w-[115px] md:h-[115px] w-[85px] h-[85px]" >
86- { imageUrl && (
87- < Image
88- src = { prePost }
89- alt = "예비사진"
90- width = { 105 }
91- height = { 105 }
92- className = "w-full h-full object-cover self-center"
93- />
94- ) }
95- </ figure >
96- </ section >
97- </ article >
98- )
99- ) }
74+ < section
75+ onClick = { ( ) => handlePost ( postId ) }
76+ className = "flex items-center gap-3 justify-between mt-3 cursor-pointer h-full"
77+ role = "link"
78+ >
79+ < div className = "flex flex-col gap-3 md:max-w-[51.25rem] sm:max-w-[27.5rem] max-w-[19.375rem] flex-grow content-between h-full" >
80+ < p className = "font-bold sm:text-xl text-lg" > { title } </ p >
81+ < div className = "font-light sm:text-[15px] text-sm md:max-w-[820px] sm:max-w-[440px] max-w-[210px] h-full" >
82+ < p
83+ className = "h-10 whitespace-pre-line"
84+ style = { {
85+ display : '-webkit-box' ,
86+ WebkitBoxOrient : 'vertical' ,
87+ WebkitLineClamp : 2 ,
88+ overflow : 'hidden' ,
89+ textOverflow : 'ellipsis' ,
90+ } }
91+ >
92+ { content }
93+ </ p >
94+ </ div >
95+ < PostInfo
96+ hasUserName = { true }
97+ userNickName = { userNickName }
98+ viewCount = { viewCount }
99+ createdAt = { createdAt }
100+ commentCount = { commentCount }
101+ />
102+ </ div >
103+ < figure className = "flex items-center flex-shrink-0 md:w-[115px] md:h-[115px] w-[85px] h-[85px]" >
104+ { imageUrls . length > 0 && (
105+ < Image
106+ src = { imageUrls [ 0 ] }
107+ alt = "예비사진"
108+ width = { 105 }
109+ height = { 105 }
110+ className = "w-full h-full object-cover self-center rounded-md"
111+ />
112+ ) }
113+ </ figure >
114+ </ section >
115+ </ article >
116+ ) ;
117+ }
118+ ) }
100119 </ >
101120 ) ;
102121}
0 commit comments