2024-04-01 14:24:10 +02:00
|
|
|
import { useState } from 'react';
|
2024-04-03 22:52:27 +02:00
|
|
|
import { Link, useLocation, useParams } from 'react-router-dom';
|
2024-03-26 16:08:06 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-04-08 16:03:32 +02:00
|
|
|
import { Role, useSubplebbit } from '@plebbit/plebbit-react-hooks';
|
2024-04-03 16:24:57 +02:00
|
|
|
import Plebbit from '@plebbit/plebbit-js/dist/browser/index.js';
|
2024-04-10 12:19:02 +02:00
|
|
|
import { getCommentMediaInfo, getHasThumbnail } from '../../lib/utils/media-utils';
|
2024-03-26 16:08:06 +01:00
|
|
|
import { getFormattedDate } from '../../lib/utils/time-utils';
|
2024-04-27 14:48:06 +02:00
|
|
|
import { isPostPageView } from '../../lib/utils/view-utils';
|
2024-04-02 12:23:18 +02:00
|
|
|
import useCountLinksInReplies from '../../hooks/use-count-links-in-replies';
|
2024-03-29 13:54:11 +01:00
|
|
|
import useReplies from '../../hooks/use-replies';
|
2024-04-27 12:41:54 +02:00
|
|
|
import useStateString from '../../hooks/use-state-string';
|
2024-04-10 13:16:07 +02:00
|
|
|
import useWindowWidth from '../../hooks/use-window-width';
|
2024-03-29 13:54:11 +01:00
|
|
|
import styles from './post.module.css';
|
2024-04-27 12:41:54 +02:00
|
|
|
import LoadingEllipsis from '../loading-ellipsis';
|
2024-03-26 16:08:06 +01:00
|
|
|
import Markdown from '../markdown';
|
2024-04-09 19:04:21 +02:00
|
|
|
import CommentMedia from '../comment-media';
|
2024-04-16 21:37:42 +02:00
|
|
|
import { canEmbed } from '../embed';
|
2024-03-29 13:54:11 +01:00
|
|
|
|
2024-04-08 16:03:32 +02:00
|
|
|
interface PostProps {
|
|
|
|
|
index?: number;
|
|
|
|
|
post?: any;
|
|
|
|
|
reply?: any;
|
|
|
|
|
roles?: Role[];
|
|
|
|
|
showAllReplies?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const PostDesktop = ({ post, roles, showAllReplies }: PostProps) => {
|
2024-03-26 16:08:06 +01:00
|
|
|
const { t } = useTranslation();
|
2024-04-26 19:13:23 +02:00
|
|
|
const { author, cid, content, link, linkHeight, linkWidth, locked, pinned, postCid, replyCount, shortCid, state, subplebbitAddress, timestamp, title } = post || {};
|
2024-04-08 16:03:32 +02:00
|
|
|
const { address, displayName, shortAddress } = author || {};
|
|
|
|
|
const authorRole = roles?.[address]?.role;
|
|
|
|
|
|
2024-04-08 12:33:59 +02:00
|
|
|
const { isDescription, isRules } = post || {}; // custom properties, not from api
|
2024-04-04 11:41:17 +02:00
|
|
|
|
2024-04-26 19:13:23 +02:00
|
|
|
const params = useParams();
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const isInPostPage = isPostPageView(location.pathname, params);
|
2024-04-04 11:41:17 +02:00
|
|
|
|
2024-04-03 16:24:57 +02:00
|
|
|
const displayTitle = title && title.length > 75 ? title?.slice(0, 75) + '...' : title;
|
2024-04-04 11:41:17 +02:00
|
|
|
const displayContent = content && !isInPostPage && content.length > 1000 ? content?.slice(0, 1000) + '(...)' : content;
|
2024-03-26 16:08:06 +01:00
|
|
|
|
2024-04-10 12:19:02 +02:00
|
|
|
const commentMediaInfo = getCommentMediaInfo(post);
|
2024-04-16 21:37:42 +02:00
|
|
|
const { type, url } = commentMediaInfo || {};
|
2024-04-25 16:11:27 +02:00
|
|
|
const embedUrl = url && new URL(url);
|
2024-03-29 13:54:11 +01:00
|
|
|
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
2024-04-01 17:39:10 +02:00
|
|
|
const [showThumbnail, setShowThumbnail] = useState(true);
|
2024-03-29 13:54:11 +01:00
|
|
|
|
2024-03-30 18:10:19 +01:00
|
|
|
const replies = useReplies(post);
|
2024-04-02 12:23:18 +02:00
|
|
|
const visibleLinkCount = useCountLinksInReplies(post, 5);
|
|
|
|
|
const totalLinkCount = useCountLinksInReplies(post);
|
|
|
|
|
const repliesCount = pinned ? replyCount : replyCount - 5;
|
|
|
|
|
const linkCount = pinned ? totalLinkCount : totalLinkCount - visibleLinkCount;
|
2024-03-30 18:10:19 +01:00
|
|
|
|
2024-04-13 16:35:52 +02:00
|
|
|
const [menuBtnRotated, setMenuBtnRotated] = useState(false);
|
|
|
|
|
|
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-04-04 11:41:17 +02:00
|
|
|
{!isInPostPage && (
|
2024-04-06 18:37:50 +02:00
|
|
|
<span className={styles.hideButtonWrapper}>
|
|
|
|
|
<span className={`${styles.hideButton} ${styles.hideThread}`} />
|
2024-04-04 11:41:17 +02:00
|
|
|
</span>
|
|
|
|
|
)}
|
2024-04-16 21:37:42 +02:00
|
|
|
{url && (
|
2024-03-29 13:54:11 +01:00
|
|
|
<div className={styles.file}>
|
|
|
|
|
<div className={styles.fileText}>
|
|
|
|
|
{t('link')}:{' '}
|
2024-04-16 21:37:42 +02:00
|
|
|
<a href={url} target='_blank' rel='noopener noreferrer'>
|
|
|
|
|
{url.length > 30 ? url.slice(0, 30) + '...' : url}
|
2024-03-29 13:54:11 +01:00
|
|
|
</a>{' '}
|
2024-04-16 21:37:42 +02:00
|
|
|
({type})
|
|
|
|
|
{!showThumbnail && (type === 'iframe' || type === 'video' || type === 'audio') && (
|
2024-04-01 14:24:10 +02:00
|
|
|
<span>
|
|
|
|
|
{' '}
|
|
|
|
|
[
|
|
|
|
|
<span className={styles.closeMedia} onClick={() => setShowThumbnail(true)}>
|
|
|
|
|
{t('close')}
|
|
|
|
|
</span>
|
|
|
|
|
]
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-04-25 16:11:27 +02:00
|
|
|
{showThumbnail && !hasThumbnail && embedUrl && canEmbed(embedUrl) && (
|
2024-04-16 17:39:33 +02:00
|
|
|
<span>
|
|
|
|
|
{' '}
|
|
|
|
|
[
|
|
|
|
|
<span className={styles.closeMedia} onClick={() => setShowThumbnail(false)}>
|
|
|
|
|
{t('open')}
|
|
|
|
|
</span>
|
|
|
|
|
]
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-03-29 13:54:11 +01:00
|
|
|
</div>
|
2024-04-16 17:39:33 +02:00
|
|
|
{(hasThumbnail || (!hasThumbnail && !showThumbnail)) && (
|
2024-04-09 19:04:21 +02:00
|
|
|
<CommentMedia
|
2024-04-01 14:24:10 +02:00
|
|
|
commentMediaInfo={commentMediaInfo}
|
2024-04-09 19:04:21 +02:00
|
|
|
isOutOfFeed={isDescription || isRules} // virtuoso wrapper unneeded
|
2024-04-01 14:24:10 +02:00
|
|
|
isReply={false}
|
|
|
|
|
linkHeight={linkHeight}
|
|
|
|
|
linkWidth={linkWidth}
|
|
|
|
|
showThumbnail={showThumbnail}
|
|
|
|
|
setShowThumbnail={setShowThumbnail}
|
|
|
|
|
/>
|
2024-03-29 13:54:11 +01:00
|
|
|
)}
|
2024-03-27 15:10:58 +01:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className={styles.postInfo}>
|
2024-03-30 18:10:19 +01:00
|
|
|
<span className={styles.checkbox}>
|
|
|
|
|
<input type='checkbox' />
|
|
|
|
|
</span>
|
|
|
|
|
{title && <span className={styles.subject}>{displayTitle} </span>}
|
2024-03-27 15:10:58 +01:00
|
|
|
<span className={styles.nameBlock}>
|
2024-04-08 16:03:32 +02:00
|
|
|
<span className={`${styles.name} ${(isDescription || isRules || authorRole) && styles.capcodeMod}`}>
|
|
|
|
|
{displayName || 'Anonymous'}
|
|
|
|
|
{authorRole && ` ## Board ${authorRole}`}{' '}
|
|
|
|
|
</span>
|
2024-04-08 12:33:59 +02:00
|
|
|
{!(isDescription || isRules) && <span className={styles.userAddress}>(u/{shortAddress}) </span>}
|
2024-03-27 15:10:58 +01:00
|
|
|
</span>
|
2024-04-13 16:35:52 +02:00
|
|
|
<span className={styles.dateTime}>
|
|
|
|
|
{getFormattedDate(timestamp)}
|
|
|
|
|
{isDescription || isRules ? '' : ' '}
|
|
|
|
|
</span>
|
2024-03-27 15:10:58 +01:00
|
|
|
<span className={styles.postNum}>
|
2024-04-08 12:33:59 +02:00
|
|
|
{!(isDescription || isRules) && (
|
|
|
|
|
<span className={styles.postNumLink}>
|
2024-04-27 14:48:06 +02:00
|
|
|
<Link to={`/p/${subplebbitAddress}/${cid}`} className={styles.linkToPost} title={t('link_to_post')} onClick={(e) => !cid && e.preventDefault()}>
|
2024-04-08 12:33:59 +02:00
|
|
|
c/
|
|
|
|
|
</Link>
|
2024-04-27 14:48:06 +02:00
|
|
|
{!cid ? (
|
2024-04-26 19:13:23 +02:00
|
|
|
<span className={styles.pendingCid}>{state === 'failed' ? 'Failed' : 'Pending'}</span>
|
|
|
|
|
) : (
|
|
|
|
|
<span className={styles.replyToPost} title={t('reply_to_post')}>
|
|
|
|
|
{shortCid}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-03-22 17:12:54 +01:00
|
|
|
</span>
|
2024-04-08 12:33:59 +02:00
|
|
|
)}
|
2024-03-27 15:10:58 +01:00
|
|
|
{pinned && (
|
2024-04-13 16:35:52 +02:00
|
|
|
<span className={`${styles.stickyIconWrapper} ${!locked && styles.addPaddingBeforeReply}`}>
|
2024-03-27 15:10:58 +01:00
|
|
|
<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 && (
|
2024-04-13 16:35:52 +02:00
|
|
|
<span className={`${styles.closedIconWrapper} ${styles.addPaddingBeforeReply} ${pinned && styles.addPaddingInBetween}`}>
|
2024-03-27 15:10:58 +01:00
|
|
|
<img src='assets/icons/closed.gif' alt='' className={styles.closedIcon} title={t('closed')} />
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
<span className={styles.replyButton}>
|
2024-04-08 12:33:59 +02:00
|
|
|
[<Link to={`/p/${subplebbitAddress}/${isDescription ? 'description' : isRules ? 'rules' : `c/${postCid}`}`}>{t('reply')}</Link>]
|
2024-03-27 15:10:58 +01:00
|
|
|
</span>
|
|
|
|
|
</span>
|
2024-04-13 16:35:52 +02:00
|
|
|
<span className={styles.postMenuBtnWrapper}>
|
|
|
|
|
<span
|
|
|
|
|
className={styles.postMenuBtn}
|
|
|
|
|
title='Post menu'
|
|
|
|
|
onClick={() => setMenuBtnRotated(!menuBtnRotated)}
|
|
|
|
|
style={{ transform: menuBtnRotated ? 'rotate(90deg)' : 'rotate(0deg)' }}
|
|
|
|
|
>
|
|
|
|
|
▶
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
2024-03-27 15:10:58 +01:00
|
|
|
</div>
|
2024-04-01 14:24:10 +02:00
|
|
|
{!content && <div className={styles.spacer} />}
|
2024-03-27 15:10:58 +01:00
|
|
|
{content && (
|
2024-03-28 17:21:27 +01:00
|
|
|
<blockquote className={styles.postMessage}>
|
|
|
|
|
<Markdown content={displayContent} />
|
2024-04-04 11:41:17 +02:00
|
|
|
{content.length > 1000 && !isInPostPage && (
|
2024-03-28 17:21:27 +01:00
|
|
|
<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
|
|
|
)}
|
2024-04-08 12:33:59 +02:00
|
|
|
{(replies.length > 5 || (pinned && replies.length > 0)) && !isInPostPage && (
|
2024-04-02 12:23:18 +02:00
|
|
|
<span className={styles.summary}>
|
2024-04-06 18:37:50 +02:00
|
|
|
<span className={styles.expandButtonWrapper}>
|
|
|
|
|
<span className={styles.expandButton} />
|
|
|
|
|
</span>
|
2024-04-02 12:23:18 +02:00
|
|
|
<span>
|
|
|
|
|
{repliesCount} replies {linkCount > 0 && `and ${linkCount} links`} omitted.{' '}
|
|
|
|
|
</span>
|
|
|
|
|
<Link to={`/p/${subplebbitAddress}/c/${cid}`}>Click here</Link> to view.
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-04-04 11:41:17 +02:00
|
|
|
{!(pinned && !isInPostPage) &&
|
|
|
|
|
replies &&
|
2024-04-08 16:08:58 +02:00
|
|
|
(showAllReplies ? replies : replies.slice(-5)).map((reply, index) => (
|
2024-03-30 18:10:19 +01:00
|
|
|
<div key={reply.cid} className={styles.replyContainer}>
|
2024-04-08 16:03:32 +02:00
|
|
|
<ReplyDesktop index={index} reply={reply} roles={roles} />
|
2024-03-30 18:10:19 +01:00
|
|
|
</div>
|
|
|
|
|
))}
|
2024-03-27 15:10:58 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-08 16:03:32 +02:00
|
|
|
const ReplyDesktop = ({ reply, roles }: PostProps) => {
|
2024-04-08 12:37:44 +02:00
|
|
|
const { t } = useTranslation();
|
2024-04-27 12:41:54 +02:00
|
|
|
const { author, cid, content, link, linkHeight, linkWidth, parentCid, pinned, postCid, shortCid, state, subplebbitAddress, timestamp } = reply || {};
|
2024-04-08 16:03:32 +02:00
|
|
|
const { address, displayName, shortAddress } = author || {};
|
|
|
|
|
const authorRole = roles?.[address]?.role;
|
2024-03-30 22:19:49 +01:00
|
|
|
|
2024-04-10 12:19:02 +02:00
|
|
|
const commentMediaInfo = getCommentMediaInfo(reply);
|
2024-04-16 21:37:42 +02:00
|
|
|
const { type, url } = commentMediaInfo || {};
|
|
|
|
|
const embedUrl = url && new URL(url);
|
2024-04-01 17:39:10 +02:00
|
|
|
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
|
|
|
|
const [showThumbnail, setShowThumbnail] = useState(true);
|
|
|
|
|
|
2024-04-03 16:24:57 +02:00
|
|
|
const isReplyingToReply = postCid !== parentCid;
|
|
|
|
|
|
2024-04-13 16:35:52 +02:00
|
|
|
const [menuBtnRotated, setMenuBtnRotated] = useState(false);
|
|
|
|
|
|
2024-04-27 12:41:54 +02:00
|
|
|
const stateString = useStateString(reply);
|
|
|
|
|
const loadingString = stateString && (
|
|
|
|
|
<div className={`${styles.stateString} ${styles.ellipsis}`}>{stateString !== 'Failed' ? <LoadingEllipsis string={stateString} /> : stateString}</div>
|
|
|
|
|
);
|
|
|
|
|
|
2024-03-30 22:19:49 +01:00
|
|
|
return (
|
2024-04-08 12:37:44 +02:00
|
|
|
<div className={styles.replyDesktop}>
|
|
|
|
|
<div className={styles.sideArrows}>{'>>'}</div>
|
2024-04-02 17:00:36 +02:00
|
|
|
<div className={styles.reply}>
|
2024-04-08 12:37:44 +02:00
|
|
|
<div className={styles.postInfo}>
|
|
|
|
|
<span className={styles.checkbox}>
|
|
|
|
|
<input type='checkbox' />
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.nameBlock}>
|
2024-04-08 16:03:32 +02:00
|
|
|
<span className={`${styles.name} ${authorRole && styles.capcodeMod}`}>
|
|
|
|
|
{displayName || 'Anonymous'}
|
|
|
|
|
{authorRole && ` ## Board ${authorRole}`}{' '}
|
|
|
|
|
</span>
|
2024-04-08 12:37:44 +02:00
|
|
|
<span className={styles.userAddress}>(u/{shortAddress}) </span>
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.dateTime}>{getFormattedDate(timestamp)} </span>
|
|
|
|
|
<span className={styles.postNum}>
|
|
|
|
|
<span className={styles.postNumLink}>
|
2024-04-27 12:41:54 +02:00
|
|
|
<Link to={`/p/${subplebbitAddress}/${cid}`} className={styles.linkToPost} title={t('link_to_post')} onClick={(e) => !cid && e.preventDefault()}>
|
2024-04-08 12:37:44 +02:00
|
|
|
c/
|
|
|
|
|
</Link>
|
2024-04-27 12:41:54 +02:00
|
|
|
{!cid ? (
|
|
|
|
|
<span className={styles.pendingCid}>{state === 'failed' ? 'Failed' : 'Pending'}</span>
|
|
|
|
|
) : (
|
|
|
|
|
<span className={styles.replyToPost} title={t('reply_to_post')}>
|
|
|
|
|
{shortCid}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-04-02 17:00:36 +02:00
|
|
|
</span>
|
2024-04-08 12:37:44 +02:00
|
|
|
{pinned && (
|
|
|
|
|
<span className={styles.stickyIconWrapper}>
|
|
|
|
|
<img src='assets/icons/sticky.gif' alt='' className={styles.stickyIcon} title={t('sticky')} />
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
2024-04-13 16:35:52 +02:00
|
|
|
<span className={styles.postMenuBtnWrapper}>
|
|
|
|
|
<span
|
|
|
|
|
className={styles.postMenuBtn}
|
|
|
|
|
title='Post menu'
|
|
|
|
|
onClick={() => setMenuBtnRotated(!menuBtnRotated)}
|
|
|
|
|
style={{ transform: menuBtnRotated ? 'rotate(90deg)' : 'rotate(0deg)' }}
|
|
|
|
|
>
|
|
|
|
|
▶
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
2024-03-30 22:19:49 +01:00
|
|
|
</div>
|
2024-04-16 21:37:42 +02:00
|
|
|
{url && (
|
2024-04-08 12:37:44 +02:00
|
|
|
<div className={styles.file}>
|
|
|
|
|
<div className={styles.fileText}>
|
|
|
|
|
{t('link')}:{' '}
|
|
|
|
|
<a href={link} target='_blank' rel='noopener noreferrer'>
|
|
|
|
|
{link.length > 30 ? link?.slice(0, 30) + '...' : link}
|
|
|
|
|
</a>
|
2024-04-16 21:37:42 +02:00
|
|
|
{!showThumbnail && (type === 'iframe' || type === 'video' || type === 'audio') && (
|
2024-04-08 12:37:44 +02:00
|
|
|
<span>
|
|
|
|
|
{' '}
|
|
|
|
|
[
|
|
|
|
|
<span className={styles.closeMedia} onClick={() => setShowThumbnail(true)}>
|
|
|
|
|
{t('close')}
|
|
|
|
|
</span>
|
|
|
|
|
]
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-04-16 21:37:42 +02:00
|
|
|
{showThumbnail && !hasThumbnail && embedUrl && canEmbed(embedUrl) && (
|
2024-04-16 17:39:33 +02:00
|
|
|
<span>
|
|
|
|
|
{' '}
|
|
|
|
|
[
|
|
|
|
|
<span className={styles.closeMedia} onClick={() => setShowThumbnail(false)}>
|
|
|
|
|
{t('open')}
|
|
|
|
|
</span>
|
|
|
|
|
]
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-04-08 12:37:44 +02:00
|
|
|
</div>
|
2024-04-16 17:39:33 +02:00
|
|
|
{(hasThumbnail || (!hasThumbnail && !showThumbnail)) && (
|
2024-04-09 19:04:21 +02:00
|
|
|
<CommentMedia
|
2024-04-08 12:37:44 +02:00
|
|
|
commentMediaInfo={commentMediaInfo}
|
|
|
|
|
isReply={true}
|
|
|
|
|
linkHeight={linkHeight}
|
|
|
|
|
linkWidth={linkWidth}
|
|
|
|
|
showThumbnail={showThumbnail}
|
|
|
|
|
setShowThumbnail={setShowThumbnail}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{content && (
|
|
|
|
|
<blockquote className={styles.postMessage}>
|
|
|
|
|
{isReplyingToReply && (
|
|
|
|
|
<>
|
|
|
|
|
<Link to={`/p/${subplebbitAddress}/c/${parentCid}`} className={styles.quoteLink}>
|
|
|
|
|
{`c/${Plebbit.getShortCid(parentCid)}`}
|
|
|
|
|
</Link>
|
|
|
|
|
<br />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
<Markdown content={content} />
|
2024-04-27 12:41:54 +02:00
|
|
|
{!cid && (
|
|
|
|
|
<>
|
|
|
|
|
<br />
|
|
|
|
|
{loadingString}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2024-04-08 12:37:44 +02:00
|
|
|
</blockquote>
|
|
|
|
|
)}
|
2024-03-30 22:19:49 +01:00
|
|
|
</div>
|
2024-04-02 17:00:36 +02:00
|
|
|
</div>
|
2024-03-30 22:19:49 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-08 16:03:32 +02:00
|
|
|
const PostMobile = ({ post, roles, showAllReplies }: PostProps) => {
|
2024-04-03 22:52:27 +02:00
|
|
|
const { t } = useTranslation();
|
2024-04-26 19:13:23 +02:00
|
|
|
const { author, cid, content, link, linkHeight, linkWidth, locked, pinned, replyCount, shortCid, state, subplebbitAddress, timestamp, title } = post || {};
|
2024-03-28 12:41:40 +01:00
|
|
|
const { address, displayName, shortAddress } = author || {};
|
2024-04-08 16:03:32 +02:00
|
|
|
const authorRole = roles?.[address]?.role;
|
|
|
|
|
|
2024-04-08 12:33:59 +02:00
|
|
|
const { isDescription, isRules } = post || {}; // custom properties, not from api
|
2024-04-07 18:16:12 +02:00
|
|
|
|
2024-04-26 19:13:23 +02:00
|
|
|
const params = useParams();
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const isInPostPage = isPostPageView(location.pathname, params);
|
|
|
|
|
|
2024-04-02 12:23:18 +02:00
|
|
|
const linkCount = useCountLinksInReplies(post);
|
2024-04-03 16:24:57 +02:00
|
|
|
const displayTitle = title && title.length > 30 ? title?.slice(0, 30) + '(...)' : title;
|
2024-04-07 18:16:12 +02:00
|
|
|
const displayContent = content && !isInPostPage && content.length > 1000 ? content?.slice(0, 1000) : content;
|
2024-03-28 12:41:40 +01:00
|
|
|
|
2024-04-10 12:19:02 +02:00
|
|
|
const commentMediaInfo = getCommentMediaInfo(post);
|
2024-03-29 20:43:58 +01:00
|
|
|
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
2024-04-01 17:39:10 +02:00
|
|
|
const [showThumbnail, setShowThumbnail] = useState(true);
|
2024-03-29 20:43:58 +01:00
|
|
|
|
2024-03-30 22:19:49 +01:00
|
|
|
const replies = useReplies(post);
|
|
|
|
|
|
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}>
|
2024-04-27 14:48:06 +02:00
|
|
|
<span className={`${styles.name} ${(isDescription || isRules || authorRole) && styles.capcodeMod}`}>
|
2024-04-08 16:03:32 +02:00
|
|
|
{displayName || 'Anonymous'}
|
|
|
|
|
{authorRole && ` ## Board ${authorRole}`}{' '}
|
|
|
|
|
</span>
|
2024-04-08 12:33:59 +02:00
|
|
|
{!(isDescription || isRules) && <span className={styles.address}>(u/{shortAddress || address?.slice(0, 12) + '...'})</span>}
|
2024-04-13 16:35:52 +02:00
|
|
|
{pinned && (
|
|
|
|
|
<span className={styles.stickyIconWrapper}>
|
|
|
|
|
<img src='assets/icons/sticky.gif' alt='' className={styles.stickyIcon} title={t('sticky')} />
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
{locked && (
|
|
|
|
|
<span className={`${styles.closedIconWrapper} ${pinned && styles.addPaddingInBetween}`}>
|
|
|
|
|
<img src='assets/icons/closed.gif' alt='' className={styles.closedIcon} title={t('closed')} />
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-03-28 12:41:40 +01:00
|
|
|
{title && (
|
|
|
|
|
<>
|
|
|
|
|
<br />
|
|
|
|
|
<span className={styles.subject}>{displayTitle}</span>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.dateTimePostNum}>
|
2024-04-08 12:33:59 +02:00
|
|
|
{getFormattedDate(timestamp)}{' '}
|
|
|
|
|
{!(isDescription || isRules) && (
|
2024-04-26 19:13:23 +02:00
|
|
|
<span className={styles.postNumLink}>
|
2024-04-27 14:48:06 +02:00
|
|
|
<Link to={`/p/${subplebbitAddress}/c/${cid}`} className={styles.linkToPost} title={t('link_to_post')} onClick={(e) => !cid && e.preventDefault()}>
|
2024-04-26 19:13:23 +02:00
|
|
|
c/
|
|
|
|
|
</Link>
|
2024-04-27 14:48:06 +02:00
|
|
|
{!cid ? (
|
2024-04-26 19:13:23 +02:00
|
|
|
<span className={styles.pendingCid}>{state === 'failed' ? 'Failed' : 'Pending'}</span>
|
|
|
|
|
) : (
|
|
|
|
|
<span className={styles.replyToPost} title={t('reply_to_post')}>
|
|
|
|
|
{shortCid}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
2024-04-08 12:33:59 +02:00
|
|
|
)}
|
2024-03-28 12:41:40 +01:00
|
|
|
</span>
|
|
|
|
|
</div>
|
2024-04-16 17:39:33 +02:00
|
|
|
{(hasThumbnail || link) && (
|
2024-04-09 19:04:21 +02:00
|
|
|
<CommentMedia
|
2024-04-01 17:39:10 +02:00
|
|
|
commentMediaInfo={commentMediaInfo}
|
2024-04-09 19:04:21 +02:00
|
|
|
isOutOfFeed={isDescription || isRules} // virtuoso wrapper unneeded
|
2024-04-01 17:39:10 +02:00
|
|
|
isReply={false}
|
|
|
|
|
linkHeight={linkHeight}
|
|
|
|
|
linkWidth={linkWidth}
|
|
|
|
|
showThumbnail={showThumbnail}
|
|
|
|
|
setShowThumbnail={setShowThumbnail}
|
|
|
|
|
/>
|
2024-03-29 20:43:58 +01:00
|
|
|
)}
|
2024-03-28 17:21:27 +01:00
|
|
|
{content && (
|
|
|
|
|
<blockquote className={`${styles.postMessage} ${styles.clampLines}`}>
|
|
|
|
|
<Markdown content={displayContent} />
|
2024-04-04 11:41:17 +02:00
|
|
|
{content.length > 1000 && !isInPostPage && (
|
2024-03-28 17:21:27 +01:00
|
|
|
<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>
|
2024-04-03 22:52:27 +02:00
|
|
|
{!isInPostPage && (
|
|
|
|
|
<div className={styles.postLink}>
|
|
|
|
|
<span className={styles.info}>
|
2024-04-08 12:33:59 +02:00
|
|
|
{replyCount > 0 && `${replyCount} Replies`}
|
2024-04-03 22:52:27 +02:00
|
|
|
{linkCount > 0 && ` / ${linkCount} Links`}
|
|
|
|
|
</span>
|
2024-04-08 17:46:36 +02:00
|
|
|
<Link to={`/p/${subplebbitAddress}/${isDescription ? 'description' : isRules ? 'rules' : `c/${cid}`}`} className='button'>
|
2024-04-03 22:52:27 +02:00
|
|
|
{t('view_thread')}
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-03-22 16:15:38 +01:00
|
|
|
</div>
|
2024-04-07 18:16:12 +02:00
|
|
|
{!(pinned && !isInPostPage) &&
|
|
|
|
|
replies &&
|
2024-04-08 16:08:58 +02:00
|
|
|
(showAllReplies ? replies : replies.slice(-5)).map((reply, index) => (
|
2024-03-30 22:19:49 +01:00
|
|
|
<div key={reply.cid} className={styles.replyContainer}>
|
2024-04-08 16:03:32 +02:00
|
|
|
<ReplyMobile index={index} reply={reply} roles={roles} />
|
2024-03-30 22:19:49 +01:00
|
|
|
</div>
|
|
|
|
|
))}
|
2024-03-22 16:15:38 +01:00
|
|
|
</div>
|
2024-03-22 15:31:02 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-08 16:03:32 +02:00
|
|
|
const ReplyMobile = ({ reply, roles }: PostProps) => {
|
2024-04-13 16:35:52 +02:00
|
|
|
const { t } = useTranslation();
|
2024-04-27 14:48:06 +02:00
|
|
|
const { author, content, cid, link, linkHeight, linkWidth, parentCid, pinned, postCid, shortCid, state, subplebbitAddress, timestamp } = reply || {};
|
2024-04-08 16:03:32 +02:00
|
|
|
const { address, displayName, shortAddress } = author || {};
|
|
|
|
|
const authorRole = roles?.[address]?.role;
|
2024-04-08 12:37:44 +02:00
|
|
|
|
2024-04-10 12:19:02 +02:00
|
|
|
const commentMediaInfo = getCommentMediaInfo(reply);
|
2024-04-08 12:37:44 +02:00
|
|
|
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
|
|
|
|
const [showThumbnail, setShowThumbnail] = useState(true);
|
|
|
|
|
|
|
|
|
|
const isReplyingToReply = postCid !== parentCid;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={styles.replyMobile}>
|
|
|
|
|
<div className={styles.reply}>
|
|
|
|
|
<div className={styles.replyContainer}>
|
|
|
|
|
<div className={styles.postInfo}>
|
|
|
|
|
<span className={styles.postMenuBtn}>...</span>
|
|
|
|
|
<span className={styles.nameBlock}>
|
2024-04-08 16:03:32 +02:00
|
|
|
<span className={`${styles.name} ${authorRole && styles.capcodeMod}`}>
|
|
|
|
|
{displayName || 'Anonymous'}
|
|
|
|
|
{authorRole && ` ## Board ${authorRole}`}{' '}
|
|
|
|
|
</span>
|
2024-04-08 12:37:44 +02:00
|
|
|
<span className={styles.address}>(u/{shortAddress})</span>
|
2024-04-13 16:35:52 +02:00
|
|
|
{pinned && (
|
|
|
|
|
<span className={styles.stickyIconWrapper}>
|
|
|
|
|
<img src='assets/icons/sticky.gif' alt='' className={styles.stickyIcon} title={t('sticky')} />
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-04-08 12:37:44 +02:00
|
|
|
</span>
|
|
|
|
|
<span className={styles.dateTimePostNum}>
|
2024-04-27 14:48:06 +02:00
|
|
|
{getFormattedDate(timestamp)}{' '}
|
|
|
|
|
<span className={styles.postNumLink}>
|
|
|
|
|
<Link to={`/p/${subplebbitAddress}/c/${cid}`} title={t('link_to_post')} onClick={(e) => !cid && e.preventDefault()}>
|
|
|
|
|
c/
|
|
|
|
|
</Link>
|
|
|
|
|
</span>
|
|
|
|
|
{!cid ? (
|
|
|
|
|
<span className={styles.pendingCid}>{state === 'failed' ? 'Failed' : 'Pending'}</span>
|
|
|
|
|
) : (
|
|
|
|
|
<span className={styles.replyToPost} title={t('reply_to_post')}>
|
|
|
|
|
{shortCid}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-04-08 12:37:44 +02:00
|
|
|
</span>
|
|
|
|
|
</div>
|
2024-04-16 17:39:33 +02:00
|
|
|
{(hasThumbnail || link) && (
|
2024-04-09 19:04:21 +02:00
|
|
|
<CommentMedia
|
2024-04-08 12:37:44 +02:00
|
|
|
commentMediaInfo={commentMediaInfo}
|
|
|
|
|
isReply={false}
|
|
|
|
|
linkHeight={linkHeight}
|
|
|
|
|
linkWidth={linkWidth}
|
|
|
|
|
showThumbnail={showThumbnail}
|
|
|
|
|
setShowThumbnail={setShowThumbnail}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{content && (
|
|
|
|
|
<blockquote className={styles.postMessage}>
|
|
|
|
|
{isReplyingToReply && (
|
|
|
|
|
<>
|
|
|
|
|
<Link to={`/p/${subplebbitAddress}/c/${parentCid}`} className={styles.quoteLink}>
|
|
|
|
|
{`c/${Plebbit.getShortCid(parentCid)}`}
|
|
|
|
|
</Link>
|
|
|
|
|
<br />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
<Markdown content={content} />
|
|
|
|
|
</blockquote>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-02 17:00:36 +02:00
|
|
|
const Post = ({ post, showAllReplies = false }: PostProps) => {
|
2024-04-08 16:03:32 +02:00
|
|
|
const subplebbit = useSubplebbit({ subplebbitAddress: post?.subplebbitAddress });
|
2024-04-10 13:16:07 +02:00
|
|
|
const isMobile = useWindowWidth() < 640;
|
2024-03-27 15:10:58 +01:00
|
|
|
return (
|
|
|
|
|
<div className={styles.thread}>
|
|
|
|
|
<div className={styles.postContainer}>
|
2024-04-10 13:16:07 +02:00
|
|
|
{isMobile ? (
|
|
|
|
|
<PostMobile post={post} roles={subplebbit?.roles} showAllReplies={showAllReplies} />
|
|
|
|
|
) : (
|
|
|
|
|
<PostDesktop post={post} roles={subplebbit?.roles} showAllReplies={showAllReplies} />
|
|
|
|
|
)}
|
2024-03-27 15:10:58 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-22 15:31:02 +01:00
|
|
|
export default Post;
|