wealth/packages/island/src/organisms/post-card/PostCard.tsx

115 lines
3.6 KiB
TypeScript

import { FlexBox } from '../../atoms/flex-box';
import { Card } from '../../molecules/card';
import { cn } from '../../tools/cn';
import { PostAccess } from './components/PostAccess';
import { PostAccessNote } from './components/PostAccessNote';
import { PostActions } from './components/PostActions';
import { PostContent } from './components/PostContent';
import { PostHead } from './components/PostHead';
import { PostLocked } from './components/PostLocked';
import { LINKED_CARD_CLASS } from './constants';
import type { PostCardProps } from './types';
/**
* The one post for the channel, the feed and the post page: free, locked, subscriber and owner
* views of text, image and prediction posts. A locked post keeps the header and swaps the body
* for the shared LockedTeaser, so locking never changes the feed's rhythm.
*
* Server-renderable: only a multi-image carousel, a frozen edit's tooltip and the desktop share
* menu are client parts. The handlers (`owner`, `onShare`, `onCopyLink`, `onImageClick`, `onCta`)
* need a client caller; a server render passes `href`, `channelHref` and `ctaHref` links instead.
*/
export function PostCard(props: PostCardProps) {
const {
author,
channelHref,
href,
publishedAt,
now,
timeLabel,
ownerTag,
premium = props.locked ?? false,
edited = false,
variant = 'compact',
predictionLabels,
owner,
onShare,
onCopyLink,
accessNote,
labels,
className,
} = props;
return (
<Card
tag="article"
className={cn('min-w-0', href && LINKED_CARD_CLASS, className)}
>
<FlexBox direction="flex-col" gap="gap-3" className="min-w-0">
<PostHead
author={author}
channelHref={channelHref}
href={href}
publishedAt={publishedAt}
now={now}
timeLabel={timeLabel}
ownerTag={ownerTag}
premium={premium}
edited={edited}
labels={labels}
/>
{props.locked ? (
<PostLocked
captionPreview={props.captionPreview}
mediaCount={props.mediaCount}
prediction={props.prediction}
viewer={props.viewer}
onCta={props.onCta}
ctaHref={props.ctaHref}
ctaFrozenReason={props.ctaFrozenReason}
ctaIndicator={props.ctaIndicator}
publishedAt={publishedAt}
now={now}
premium={premium}
predictionLabels={predictionLabels}
labels={labels}
/>
) : (
<PostContent
text={props.text}
images={props.images}
onImageClick={props.onImageClick}
prediction={props.prediction}
variant={variant}
href={href}
publishedAt={publishedAt}
now={now}
premium={premium}
onClosePrediction={owner?.onClosePrediction}
predictionLabels={predictionLabels}
labels={labels}
/>
)}
{owner?.accessFrozen && props.prediction == null && (
<PostAccess
premium={premium}
reason={owner.editFrozenReason ?? labels.owner.editFrozen}
labels={labels}
/>
)}
{!props.locked && accessNote != null && (
<PostAccessNote>{accessNote}</PostAccessNote>
)}
<PostActions
owner={owner}
onShare={onShare}
onCopyLink={onCopyLink}
premium={premium}
isPrediction={props.prediction != null}
labels={labels}
/>
</FlexBox>
</Card>
);
}