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';
|
|
|
|
|
import styles from './post.module.css';
|
2024-03-22 16:15:38 +01:00
|
|
|
import useReplies from '../../hooks/use-replies';
|
|
|
|
|
import { getLinkMediaInfoMemoized } from '../../lib/utils/media-utils';
|
2024-03-26 16:08:06 +01:00
|
|
|
import { getFormattedDate } from '../../lib/utils/time-utils';
|
|
|
|
|
import Markdown from '../markdown';
|
2024-03-22 15:31:02 +01:00
|
|
|
|
|
|
|
|
const Post = ({ post }: Comment) => {
|
2024-03-26 16:08:06 +01:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const { author, cid, content, link, 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);
|
|
|
|
|
const linkMediaInfo = getLinkMediaInfoMemoized(link);
|
2024-03-26 16:08:06 +01:00
|
|
|
|
2024-03-22 15:31:02 +01:00
|
|
|
return (
|
2024-03-22 16:15:38 +01:00
|
|
|
<div className={styles.thread}>
|
|
|
|
|
<div className={styles.postContainer}>
|
|
|
|
|
<div className={styles.postDesktop}>
|
2024-03-26 16:08:06 +01:00
|
|
|
<div className={styles.hrWrapper}>
|
|
|
|
|
<hr />
|
|
|
|
|
</div>
|
2024-03-22 16:15:38 +01:00
|
|
|
{linkMediaInfo?.url && (
|
|
|
|
|
<div className={styles.link}>
|
2024-03-26 16:08:06 +01:00
|
|
|
{t('link')}:{' '}
|
2024-03-22 16:15:38 +01:00
|
|
|
<a href={linkMediaInfo?.url} target='_blank' rel='noopener noreferrer'>
|
|
|
|
|
{linkMediaInfo.url.length > 30 ? linkMediaInfo?.url.slice(0, 30) + '...' : linkMediaInfo?.url}
|
|
|
|
|
</a>{' '}
|
|
|
|
|
({linkMediaInfo?.type})
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-03-22 17:12:54 +01:00
|
|
|
<div className={styles.postInfo}>
|
|
|
|
|
{title && <span className={styles.subject}>{title.length > 75 ? title.slice(0, 75) + '...' : title}</span>}{' '}
|
|
|
|
|
<span className={styles.nameBlock}>
|
|
|
|
|
<span className={styles.name}>{displayName || 'Anonymous'} </span>
|
2024-03-26 16:08:06 +01:00
|
|
|
<span className={styles.userAddress}>(u/{shortAddress}) </span>
|
2024-03-22 17:12:54 +01:00
|
|
|
</span>
|
2024-03-26 16:08:06 +01:00
|
|
|
<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}
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
{pinned && (
|
|
|
|
|
<span className={styles.stickyIconWrapper}>
|
|
|
|
|
<img src='assets/icons/sticky.gif' alt='' className={styles.stickyIcon} title={t('sticky')} />
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
{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>
|
2024-03-26 16:58:39 +01:00
|
|
|
{content && (
|
|
|
|
|
<div className={styles.postMessage}>
|
2024-03-26 16:08:06 +01:00
|
|
|
<blockquote>
|
|
|
|
|
<Markdown content={content} />
|
|
|
|
|
</blockquote>
|
2024-03-26 16:58:39 +01:00
|
|
|
</div>
|
|
|
|
|
)}
|
2024-03-22 16:15:38 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-03-22 15:31:02 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Post;
|