mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
refactor(post): abstract post content on desktop
This commit is contained in:
@@ -26,16 +26,17 @@ interface PostProps {
|
|||||||
reply?: any;
|
reply?: any;
|
||||||
roles?: Role[];
|
roles?: Role[];
|
||||||
showAllReplies?: boolean;
|
showAllReplies?: boolean;
|
||||||
stateString?: string;
|
|
||||||
openReplyModal?: (cid: string) => void;
|
openReplyModal?: (cid: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PostInfoDesktop = ({ isInPostPage, openReplyModal, post, roles, stateString }: PostProps) => {
|
const PostInfoDesktop = ({ isInPostPage, openReplyModal, post, roles }: PostProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { author, cid, locked, pinned, postCid, shortCid, state, subplebbitAddress, timestamp, title } = post || {};
|
const { author, cid, locked, pinned, postCid, shortCid, state, subplebbitAddress, timestamp, title } = post || {};
|
||||||
const { address, displayName, shortAddress } = author || {};
|
const { address, displayName, shortAddress } = author || {};
|
||||||
const { isDescription, isRules } = post || {}; // custom properties, not from api
|
const { isDescription, isRules } = post || {}; // custom properties, not from api
|
||||||
|
|
||||||
|
const stateString = useStateString(post);
|
||||||
|
|
||||||
const isReply = post?.parentCid;
|
const isReply = post?.parentCid;
|
||||||
|
|
||||||
const shortDisplayName = displayName?.trim().length > 20 ? displayName?.trim().slice(0, 20).trim() + '...' : displayName?.trim();
|
const shortDisplayName = displayName?.trim().length > 20 ? displayName?.trim().slice(0, 20).trim() + '...' : displayName?.trim();
|
||||||
@@ -185,16 +186,52 @@ const PostMediaDesktop = ({ post }: PostProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const PostDesktop = ({ isInPostPage, isPendingPostPage, openReplyModal, post, roles, showAllReplies, stateString }: PostProps) => {
|
const PostMessageDesktop = ({ isInPostPage, post }: PostProps) => {
|
||||||
const { cid, content, pinned, replyCount, state, subplebbitAddress } = post || {};
|
const { cid, content, parentCid, postCid, state, subplebbitAddress } = post || {};
|
||||||
const { isDescription, isRules } = post || {}; // custom properties, not from api
|
|
||||||
|
|
||||||
const displayContent = content && !isInPostPage && content.length > 1000 ? content?.slice(0, 1000) + '(...)' : content;
|
const displayContent = content && !isInPostPage && content.length > 1000 ? content?.slice(0, 1000) + '(...)' : content;
|
||||||
|
|
||||||
|
const isReply = parentCid;
|
||||||
|
const isReplyingToReply = postCid !== parentCid;
|
||||||
|
|
||||||
|
const stateString = useStateString(post);
|
||||||
|
|
||||||
const loadingString = stateString && (
|
const loadingString = stateString && (
|
||||||
<div className={`${styles.stateString} ${styles.ellipsis}`}>{stateString !== 'Failed' ? <LoadingEllipsis string={stateString} /> : stateString}</div>
|
<div className={`${styles.stateString} ${styles.ellipsis}`}>{stateString !== 'Failed' ? <LoadingEllipsis string={stateString} /> : stateString}</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
content && (
|
||||||
|
<blockquote className={styles.postMessage}>
|
||||||
|
{isReply && isReplyingToReply && (
|
||||||
|
<>
|
||||||
|
<Link to={`/p/${subplebbitAddress}/c/${parentCid}`} className={styles.quoteLink}>
|
||||||
|
{`c/${parentCid && Plebbit.getShortCid(parentCid)}`}
|
||||||
|
</Link>
|
||||||
|
<br />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<Markdown content={displayContent} />
|
||||||
|
{!isReply && content.length > 1000 && !isInPostPage && (
|
||||||
|
<span className={styles.abbr}>
|
||||||
|
<br />
|
||||||
|
<Trans i18nKey={'comment_too_long'} shouldUnescape={true} components={{ 1: <Link to={`/p/${subplebbitAddress}/c/${cid}`} /> }} />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{!cid && state === 'pending' && stateString !== 'Failed' && (
|
||||||
|
<>
|
||||||
|
<br />
|
||||||
|
{loadingString}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</blockquote>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const PostDesktop = ({ isInPostPage, isPendingPostPage, openReplyModal, post, roles, showAllReplies }: PostProps) => {
|
||||||
|
const { cid, content, pinned, replyCount, subplebbitAddress } = post || {};
|
||||||
|
const { isDescription, isRules } = post || {}; // custom properties, not from api
|
||||||
|
|
||||||
const replies = useReplies(post);
|
const replies = useReplies(post);
|
||||||
const visiblelinksCount = useCountLinksInReplies(post, 5);
|
const visiblelinksCount = useCountLinksInReplies(post, 5);
|
||||||
const totallinksCount = useCountLinksInReplies(post);
|
const totallinksCount = useCountLinksInReplies(post);
|
||||||
@@ -212,32 +249,9 @@ const PostDesktop = ({ isInPostPage, isPendingPostPage, openReplyModal, post, ro
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
<PostMediaDesktop post={post} />
|
<PostMediaDesktop post={post} />
|
||||||
<PostInfoDesktop
|
<PostInfoDesktop isInPostPage={isInPostPage} isPendingPostPage={isPendingPostPage} openReplyModal={openReplyModal} post={post} roles={roles} />
|
||||||
isInPostPage={isInPostPage}
|
|
||||||
isPendingPostPage={isPendingPostPage}
|
|
||||||
openReplyModal={openReplyModal}
|
|
||||||
post={post}
|
|
||||||
roles={roles}
|
|
||||||
stateString={stateString}
|
|
||||||
/>
|
|
||||||
{!content && <div className={styles.spacer} />}
|
{!content && <div className={styles.spacer} />}
|
||||||
{content && (
|
<PostMessageDesktop isInPostPage={isInPostPage} post={post} />
|
||||||
<blockquote className={styles.postMessage}>
|
|
||||||
<Markdown content={displayContent} />
|
|
||||||
{content.length > 1000 && !isInPostPage && (
|
|
||||||
<span className={styles.abbr}>
|
|
||||||
<br />
|
|
||||||
<Trans i18nKey={'comment_too_long'} shouldUnescape={true} components={{ 1: <Link to={`/p/${subplebbitAddress}/c/${cid}`} /> }} />
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
{!cid && state === 'pending' && stateString !== 'Failed' && (
|
|
||||||
<>
|
|
||||||
<br />
|
|
||||||
{loadingString}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</blockquote>
|
|
||||||
)}
|
|
||||||
{!isDescription && !isRules && !isPendingPostPage && (replies.length > 5 || (pinned && replies.length > 0)) && !isInPostPage && (
|
{!isDescription && !isRules && !isPendingPostPage && (replies.length > 5 || (pinned && replies.length > 0)) && !isInPostPage && (
|
||||||
<span className={styles.summary}>
|
<span className={styles.summary}>
|
||||||
<span className={styles.expandButtonWrapper}>
|
<span className={styles.expandButtonWrapper}>
|
||||||
@@ -270,53 +284,19 @@ const PostDesktop = ({ isInPostPage, isPendingPostPage, openReplyModal, post, ro
|
|||||||
};
|
};
|
||||||
|
|
||||||
const ReplyDesktop = ({ isInPostPage, isPendingPostPage, reply, roles, openReplyModal }: PostProps) => {
|
const ReplyDesktop = ({ isInPostPage, isPendingPostPage, reply, roles, openReplyModal }: PostProps) => {
|
||||||
const { cid, content, parentCid, postCid, state, subplebbitAddress } = reply || {};
|
|
||||||
|
|
||||||
const isReplyingToReply = postCid !== parentCid;
|
|
||||||
|
|
||||||
const stateString = useStateString(reply);
|
|
||||||
const loadingString = stateString && (
|
|
||||||
<div className={`${styles.stateString} ${styles.ellipsis}`}>{stateString !== 'Failed' ? <LoadingEllipsis string={stateString} /> : stateString}</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.replyDesktop}>
|
<div className={styles.replyDesktop}>
|
||||||
<div className={styles.sideArrows}>{'>>'}</div>
|
<div className={styles.sideArrows}>{'>>'}</div>
|
||||||
<div className={styles.reply}>
|
<div className={styles.reply}>
|
||||||
<PostInfoDesktop
|
<PostInfoDesktop isInPostPage={isInPostPage} isPendingPostPage={isPendingPostPage} openReplyModal={openReplyModal} post={reply} roles={roles} />
|
||||||
isInPostPage={isInPostPage}
|
|
||||||
isPendingPostPage={isPendingPostPage}
|
|
||||||
openReplyModal={openReplyModal}
|
|
||||||
post={reply}
|
|
||||||
roles={roles}
|
|
||||||
stateString={stateString}
|
|
||||||
/>
|
|
||||||
<PostMediaDesktop post={reply} />
|
<PostMediaDesktop post={reply} />
|
||||||
{content && (
|
<PostMessageDesktop isInPostPage={isInPostPage} post={reply} />
|
||||||
<blockquote className={styles.postMessage}>
|
|
||||||
{isReplyingToReply && (
|
|
||||||
<>
|
|
||||||
<Link to={`/p/${subplebbitAddress}/c/${parentCid}`} className={styles.quoteLink}>
|
|
||||||
{`c/${parentCid && Plebbit.getShortCid(parentCid)}`}
|
|
||||||
</Link>
|
|
||||||
<br />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<Markdown content={content} />
|
|
||||||
{!cid && state === 'pending' && stateString !== 'Failed' && (
|
|
||||||
<>
|
|
||||||
<br />
|
|
||||||
{loadingString}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</blockquote>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const PostMobile = ({ isInPostPage, isPendingPostPage, openReplyModal, post, roles, showAllReplies, stateString }: PostProps) => {
|
const PostMobile = ({ isInPostPage, isPendingPostPage, openReplyModal, post, roles, showAllReplies }: PostProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { author, cid, content, link, linkHeight, linkWidth, locked, pinned, replyCount, shortCid, state, subplebbitAddress, timestamp, title } = post || {};
|
const { author, cid, content, link, linkHeight, linkWidth, locked, pinned, replyCount, shortCid, state, subplebbitAddress, timestamp, title } = post || {};
|
||||||
const { address, displayName, shortAddress } = author || {};
|
const { address, displayName, shortAddress } = author || {};
|
||||||
@@ -339,6 +319,8 @@ const PostMobile = ({ isInPostPage, isPendingPostPage, openReplyModal, post, rol
|
|||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
const accountShortAddress = account?.author?.shortAddress;
|
const accountShortAddress = account?.author?.shortAddress;
|
||||||
|
|
||||||
|
const stateString = useStateString(post);
|
||||||
|
|
||||||
const loadingString = stateString && (
|
const loadingString = stateString && (
|
||||||
<div className={`${styles.stateString} ${styles.ellipsis}`}>{stateString !== 'Failed' ? <LoadingEllipsis string={stateString} /> : stateString}</div>
|
<div className={`${styles.stateString} ${styles.ellipsis}`}>{stateString !== 'Failed' ? <LoadingEllipsis string={stateString} /> : stateString}</div>
|
||||||
);
|
);
|
||||||
@@ -452,7 +434,7 @@ const PostMobile = ({ isInPostPage, isPendingPostPage, openReplyModal, post, rol
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const ReplyMobile = ({ openReplyModal, reply, roles, stateString }: PostProps) => {
|
const ReplyMobile = ({ openReplyModal, reply, roles }: PostProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { author, content, cid, link, linkHeight, linkWidth, parentCid, pinned, postCid, shortCid, state, subplebbitAddress, timestamp } = reply || {};
|
const { author, content, cid, link, linkHeight, linkWidth, parentCid, pinned, postCid, shortCid, state, subplebbitAddress, timestamp } = reply || {};
|
||||||
const { address, displayName, shortAddress } = author || {};
|
const { address, displayName, shortAddress } = author || {};
|
||||||
@@ -469,6 +451,8 @@ const ReplyMobile = ({ openReplyModal, reply, roles, stateString }: PostProps) =
|
|||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
const accountShortAddress = account?.author?.shortAddress;
|
const accountShortAddress = account?.author?.shortAddress;
|
||||||
|
|
||||||
|
const stateString = useStateString(reply);
|
||||||
|
|
||||||
const loadingString = stateString && (
|
const loadingString = stateString && (
|
||||||
<div className={`${styles.stateString} ${styles.ellipsis}`}>{stateString !== 'Failed' ? <LoadingEllipsis string={stateString} /> : stateString}</div>
|
<div className={`${styles.stateString} ${styles.ellipsis}`}>{stateString !== 'Failed' ? <LoadingEllipsis string={stateString} /> : stateString}</div>
|
||||||
);
|
);
|
||||||
@@ -551,8 +535,6 @@ const Post = ({ post, showAllReplies = false, openReplyModal }: PostProps) => {
|
|||||||
const isInPostPage = isPostPageView(location.pathname, params);
|
const isInPostPage = isPostPageView(location.pathname, params);
|
||||||
const isPendingPostPage = isPendingPostView(location.pathname, params);
|
const isPendingPostPage = isPendingPostView(location.pathname, params);
|
||||||
|
|
||||||
const stateString = useStateString(post);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.thread}>
|
<div className={styles.thread}>
|
||||||
<div className={styles.postContainer}>
|
<div className={styles.postContainer}>
|
||||||
@@ -563,7 +545,6 @@ const Post = ({ post, showAllReplies = false, openReplyModal }: PostProps) => {
|
|||||||
post={post}
|
post={post}
|
||||||
roles={subplebbit?.roles}
|
roles={subplebbit?.roles}
|
||||||
showAllReplies={showAllReplies}
|
showAllReplies={showAllReplies}
|
||||||
stateString={stateString}
|
|
||||||
openReplyModal={openReplyModal}
|
openReplyModal={openReplyModal}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -573,7 +554,6 @@ const Post = ({ post, showAllReplies = false, openReplyModal }: PostProps) => {
|
|||||||
post={post}
|
post={post}
|
||||||
roles={subplebbit?.roles}
|
roles={subplebbit?.roles}
|
||||||
showAllReplies={showAllReplies}
|
showAllReplies={showAllReplies}
|
||||||
stateString={stateString}
|
|
||||||
openReplyModal={openReplyModal}
|
openReplyModal={openReplyModal}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user