function PostCard({
post,
sort,
screenSection,
isOpenNewTab,
highlightKeyword,
}: PostCardProps) {
const {
postUuid,
body,
previewImageUrls,
profile,
displayDateTime,
title,
visible,
locked,
attachedAudio,
viewCountCache,
likedCountCache,
postCommentsCount,
isSale,
pointAmount,
} = post;
const { userProfile } = useUserProfile();
const permalink = profile.creatorPermalink;
const [isDesktopView, setIsDesktopView] = useState<boolean>(false);
const setViewport = () => {
const viewportWidth = window.innerWidth;
setIsDesktopView(viewportWidth > 768);
};
const titleLineClamp = !body ? 'text-ellipsis-2' : 'text-ellipsis-1';
const bodyLineClamp =
// m : 멤버공개 포스트 1줄 말줄임 / 전체공개 포스트 2줄 말줄임
// pc : 멤버공개, 전체공개 포스트 2줄 말줄임
isDesktopView || visible === 'MEMBER'
? 'text-ellipsis-1'
: 'text-ellipsis-2';
const hasThumbnail = previewImageUrls?.length > 0;
const onCardClick = () => {
isOpenNewTab
? window.open(`/creator/${permalink}/posts/${postUuid}`, '_blank')
: Router.push(`/creator/${permalink}/posts/${postUuid}`);
};
useEffect(() => {
setViewport();
window.addEventListener('resize', setViewport);
return () => {
window.removeEventListener('resize', setViewport);
};
}, []);
const showUtilVisibleInfo = isSale || visible !== 'PUBLIC';
return (
<DataLogging eventName="Clicked Creator Post" trackData={loggingData}>
<button
type="button"
aria-label="post card"
className="block text-left w-full"
onClick={onCardClick}
>
<div className="flex gap-x-[16px]">
<div className="w-full h-[73px] xl:h-auto break-all">
<h2
className={`overflow-hidden font_title_bold_md xl:font_title_bold_lg content_secondary ${titleLineClamp}`}
>
{!!attachedAudio && (
<AudioSolid className="inline-block mr-[7px] shrink-0 w-[20px] h-[20px] content_accent" />
)}
{highlightKeyword ? (
<HighlightText
originText={title}
highlightKeyword={highlightKeyword}
/>
) : (
title
)}
</h2>
<p
className={`mt-[4px] mb-[18px] xl:mt-[6px] overflow-hidden font_label_regular_lg
content_quaternary ${bodyLineClamp} xl:text-ellipsis-2`}
>
{body}
</p>
</div>
{hasThumbnail && (
<div className="shrink-0 relative w-[72px] md:w-[90px] h-[72px] md:h-[90px] rounded-[8px]">
<Image
src={previewImageUrls[0]}
alt={title}
className="rounded-[8px]"
fill
blurDataURL={previewImageUrls[0]}
placeholder="blur"
sizes="(max-width: 500px) 72px, 90px"
/>
<div className="absolute top-0 left-0 w-full h-full border border_black_opacity rounded-[8px]" />
</div>
)}
</div>
<div>
<PostWriteInfo
writerName={profile.userName}
publishDateTime={displayDateTime}
/>
<PostResponseInfo
isSale={isSale}
view={viewCountCache}
comment={postCommentsCount}
like={likedCountCache}
point={pointAmount}
visible={visible}
isPublic={showUtilVisibleInfo}
/>
</div>
</button>
</DataLogging>
);
}