2024-03-26 16:08:06 +01:00
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-03-22 15:31:02 +01:00
|
|
|
import { Comment } from '@plebbit/plebbit-react-hooks';
|
2024-03-29 13:54:11 +01:00
|
|
|
import { getCommentMediaInfoMemoized, getHasThumbnail } from '../../lib/utils/media-utils';
|
2024-03-26 16:08:06 +01:00
|
|
|
import { getFormattedDate } from '../../lib/utils/time-utils';
|
2024-03-29 13:54:11 +01:00
|
|
|
import useReplies from '../../hooks/use-replies';
|
|
|
|
|
import styles from './post.module.css';
|
2024-03-26 16:08:06 +01:00
|
|
|
import Markdown from '../markdown';
|
2024-03-29 13:54:11 +01:00
|
|
|
import { Thumbnail } from '../media';
|
|
|
|
|
|
2024-03-28 12:41:40 +01:00
|
|
|
import { countLinksInCommentReplies } from '../../lib/utils/comment-utils';
|
2024-03-22 15:31:02 +01:00
|
|
|
|
2024-03-27 15:10:58 +01:00
|
|
|
const PostDesktop = ({ post }: Comment) => {
|
2024-03-26 16:08:06 +01:00
|
|
|
const { t } = useTranslation();
|
2024-03-29 13:54:11 +01:00
|
|
|
const { author, cid, content, link, linkHeight, linkWidth, locked, pinned, postCid, shortCid, subplebbitAddress, timestamp, title } = post || {};
|
2024-03-22 17:12:54 +01:00
|
|
|
const { displayName, shortAddress } = author || {};
|
2024-03-22 16:15:38 +01:00
|
|
|
const replies = useReplies(post);
|
2024-03-28 12:41:40 +01:00
|
|
|
const displayTitle = title && title.length > 75 ? title.slice(0, 75) + '...' : title;
|
2024-03-28 17:21:27 +01:00
|
|
|
const displayContent = content && content.length > 1000 ? content.slice(0, 1000) + '(...)' : content;
|
2024-03-26 16:08:06 +01:00
|
|
|
|
2024-03-29 13:54:11 +01:00
|
|
|
const commentMediaInfo = getCommentMediaInfoMemoized(post);
|
|
|
|
|
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
|
|
|
|
|
2024-03-22 15:31:02 +01:00
|
|
|
return (
|
2024-03-27 15:10:58 +01:00
|
|
|
<div className={styles.postDesktop}>
|
|
|
|
|
<div className={styles.hrWrapper}>
|
|
|
|
|
<hr />
|
|
|
|
|
</div>
|
2024-03-29 13:54:11 +01:00
|
|
|
<span className={styles.threadHideButtonWrapper}>
|
|
|
|
|
<span className={`${styles.threadHideButton} ${styles.hideThread}`} />
|
|
|
|
|
</span>
|
|
|
|
|
{commentMediaInfo?.url && (
|
|
|
|
|
<div className={styles.file}>
|
|
|
|
|
<div className={styles.fileText}>
|
|
|
|
|
{t('link')}:{' '}
|
|
|
|
|
<a href={commentMediaInfo?.url} target='_blank' rel='noopener noreferrer'>
|
|
|
|
|
{commentMediaInfo.url.length > 30 ? commentMediaInfo?.url.slice(0, 30) + '...' : commentMediaInfo?.url}
|
|
|
|
|
</a>{' '}
|
|
|
|
|
({commentMediaInfo?.type})
|
|
|
|
|
</div>
|
|
|
|
|
{hasThumbnail && (
|
|
|
|
|
<span className={styles.fileThumb}>
|
|
|
|
|
<Thumbnail
|
|
|
|
|
cid={cid}
|
|
|
|
|
commentMediaInfo={commentMediaInfo}
|
|
|
|
|
isReply={false}
|
|
|
|
|
link={link}
|
|
|
|
|
linkHeight={linkHeight}
|
|
|
|
|
linkWidth={linkWidth}
|
|
|
|
|
subplebbitAddress={subplebbitAddress}
|
|
|
|
|
/>
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-03-27 15:10:58 +01:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className={styles.postInfo}>
|
2024-03-28 12:41:40 +01:00
|
|
|
{title && <span className={styles.subject}>{displayTitle}</span>}{' '}
|
2024-03-27 15:10:58 +01:00
|
|
|
<span className={styles.nameBlock}>
|
|
|
|
|
<span className={styles.name}>{displayName || 'Anonymous'} </span>
|
|
|
|
|
<span className={styles.userAddress}>(u/{shortAddress}) </span>
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.dateTime}>{getFormattedDate(timestamp)} </span>
|
|
|
|
|
<span className={styles.postNum}>
|
|
|
|
|
<span className={styles.postNumLink}>
|
|
|
|
|
<Link to={`/p/${subplebbitAddress}/c/${cid}`} className={styles.linkToPost} title={t('link_to_post')}>
|
|
|
|
|
c/
|
|
|
|
|
</Link>
|
|
|
|
|
<span className={styles.replyToPost} title={t('reply_to_post')}>
|
|
|
|
|
{shortCid}
|
2024-03-22 17:12:54 +01:00
|
|
|
</span>
|
2024-03-27 15:10:58 +01:00
|
|
|
</span>
|
|
|
|
|
{pinned && (
|
|
|
|
|
<span className={styles.stickyIconWrapper}>
|
|
|
|
|
<img src='assets/icons/sticky.gif' alt='' className={styles.stickyIcon} title={t('sticky')} />
|
2024-03-26 16:08:06 +01:00
|
|
|
</span>
|
2024-03-26 16:58:39 +01:00
|
|
|
)}
|
2024-03-27 15:10:58 +01:00
|
|
|
{locked && (
|
|
|
|
|
<span className={styles.closedIconWrapper}>
|
|
|
|
|
<img src='assets/icons/closed.gif' alt='' className={styles.closedIcon} title={t('closed')} />
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
<span className={styles.replyButton}>
|
|
|
|
|
[<Link to={`/p/${subplebbitAddress}/c/${postCid}`}>{t('reply')}</Link>]
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.postMenuBtn}>▶</span>
|
|
|
|
|
</div>
|
|
|
|
|
{content && (
|
2024-03-28 17:21:27 +01:00
|
|
|
<blockquote className={styles.postMessage}>
|
|
|
|
|
<Markdown content={displayContent} />
|
|
|
|
|
{content.length > 1000 && (
|
|
|
|
|
<span className={styles.abbr}>
|
|
|
|
|
<br />
|
|
|
|
|
Comment too long. <Link to={`/p/${subplebbitAddress}/c/${cid}`}>Click here</Link> to view the full text.
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</blockquote>
|
2024-03-27 15:10:58 +01:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const PostMobile = ({ post }: Comment) => {
|
2024-03-28 12:41:40 +01:00
|
|
|
const { author, cid, content, 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;
|
2024-03-28 17:21:27 +01:00
|
|
|
const displayContent = content && content.length > 1000 ? content.slice(0, 1000) : content;
|
2024-03-28 12:41:40 +01:00
|
|
|
|
2024-03-27 15:10:58 +01:00
|
|
|
return (
|
|
|
|
|
<div className={styles.postMobile}>
|
2024-03-28 12:41:40 +01:00
|
|
|
<div className={styles.hrWrapper}>
|
|
|
|
|
<hr />
|
|
|
|
|
</div>
|
2024-03-27 15:10:58 +01:00
|
|
|
<div className={styles.thread}>
|
|
|
|
|
<div className={styles.postContainer}>
|
2024-03-28 12:41:40 +01:00
|
|
|
<div className={styles.postOp}>
|
|
|
|
|
<div className={styles.postInfo}>
|
|
|
|
|
<span className={styles.postMenuBtn} title='Post menu'>
|
|
|
|
|
...
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.nameBlock}>
|
|
|
|
|
<span className={styles.name}>{displayName || 'Anonymous'} </span>
|
|
|
|
|
<span className={styles.address}>(u/{shortAddress || address.slice(0, 12) + '...'})</span>
|
|
|
|
|
{title && (
|
|
|
|
|
<>
|
|
|
|
|
<br />
|
|
|
|
|
<span className={styles.subject}>{displayTitle}</span>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.dateTimePostNum}>
|
|
|
|
|
{getFormattedDate(timestamp)} <span className={styles.linkToPost}>c/</span>
|
|
|
|
|
<span className={styles.replyToPost}>{shortCid}</span>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2024-03-28 17:21:27 +01:00
|
|
|
{content && (
|
|
|
|
|
<blockquote className={`${styles.postMessage} ${styles.clampLines}`}>
|
|
|
|
|
<Markdown content={displayContent} />
|
|
|
|
|
{content.length > 1000 && (
|
|
|
|
|
<span className={styles.abbr}>
|
|
|
|
|
<br />
|
|
|
|
|
Comment too long. <Link to={`/p/${subplebbitAddress}/c/${cid}`}>Click here</Link> to view the full text.
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</blockquote>
|
|
|
|
|
)}
|
2024-03-28 12:41:40 +01:00
|
|
|
</div>
|
|
|
|
|
<div className={styles.postLink}>
|
|
|
|
|
<span className={styles.info}>
|
|
|
|
|
{replyCount} Replies
|
|
|
|
|
{linkCount > 0 && ` / ${linkCount} Links`}
|
|
|
|
|
</span>
|
|
|
|
|
<Link to={`/p/${subplebbitAddress}/c/${cid}`} className='button'>
|
|
|
|
|
View Thread
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
2024-03-22 16:15:38 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-03-22 15:31:02 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-27 15:10:58 +01:00
|
|
|
const Post = ({ post }: Comment) => {
|
|
|
|
|
return (
|
|
|
|
|
<div className={styles.thread}>
|
|
|
|
|
<div className={styles.postContainer}>
|
|
|
|
|
<PostDesktop post={post} />
|
|
|
|
|
<PostMobile post={post} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-22 15:31:02 +01:00
|
|
|
export default Post;
|