import { Link } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { Comment } from '@plebbit/plebbit-react-hooks'; import { getCommentMediaInfoMemoized, getHasThumbnail } from '../../lib/utils/media-utils'; import { getFormattedDate } from '../../lib/utils/time-utils'; import useReplies from '../../hooks/use-replies'; import styles from './post.module.css'; import Markdown from '../markdown'; import { Thumbnail } from '../media'; import { countLinksInCommentReplies } from '../../lib/utils/comment-utils'; const ReplyDesktop = ({ reply }: Comment) => { const { content, link, linkHeight, linkWidth, shortCid, subplebbitAddress, timestamp } = reply || {}; return (
{'>>'}
{content}
); }; const PostDesktop = ({ post }: Comment) => { const { t } = useTranslation(); const { author, cid, content, link, linkHeight, linkWidth, locked, pinned, postCid, shortCid, subplebbitAddress, timestamp, title } = post || {}; const { displayName, shortAddress } = author || {}; const displayTitle = title && title.length > 75 ? title.slice(0, 75) + '...' : title; const displayContent = content && content.length > 1000 ? content.slice(0, 1000) + '(...)' : content; const commentMediaInfo = getCommentMediaInfoMemoized(post); const hasThumbnail = getHasThumbnail(commentMediaInfo, link); return (

{commentMediaInfo?.url && (
{t('link')}:{' '} {commentMediaInfo.url.length > 30 ? commentMediaInfo?.url.slice(0, 30) + '...' : commentMediaInfo?.url} {' '} ({commentMediaInfo?.type})
{hasThumbnail && ( )}
)}
{title && {displayTitle}}{' '} {displayName || 'Anonymous'} (u/{shortAddress}) {getFormattedDate(timestamp)} c/ {shortCid} {pinned && ( )} {locked && ( )} [{t('reply')}]
{content && (
{content.length > 1000 && (
Comment too long. Click here to view the full text.
)}
)}
); }; const PostMobile = ({ post }: Comment) => { const { author, cid, content, link, linkHeight, linkWidth, replyCount, shortCid, subplebbitAddress, timestamp, title } = post || {}; const { address, displayName, shortAddress } = author || {}; const linkCount = countLinksInCommentReplies(post); const displayTitle = title && title.length > 30 ? title.slice(0, 30) + '(...)' : title; const displayContent = content && content.length > 1000 ? content.slice(0, 1000) : content; const commentMediaInfo = getCommentMediaInfoMemoized(post); const hasThumbnail = getHasThumbnail(commentMediaInfo, link); return (

... {displayName || 'Anonymous'} (u/{shortAddress || address.slice(0, 12) + '...'}) {title && ( <>
{displayTitle} )}
{getFormattedDate(timestamp)} c/ {shortCid}
{hasThumbnail && ( {commentMediaInfo?.type &&
{commentMediaInfo.type}
}
)} {content && (
{content.length > 1000 && (
Comment too long. Click here to view the full text.
)}
)}
{replyCount} Replies {linkCount > 0 && ` / ${linkCount} Links`} View Thread
); }; const Post = ({ post }: Comment) => { const replies = useReplies(post); return (
{replies.map((reply) => (
))}
); }; export default Post;