2024-12-05 15:37:23 +01:00
|
|
|
import { useState } from 'react';
|
2025-02-22 22:22:42 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-05-17 15:29:03 +02:00
|
|
|
import { Link, useLocation, useParams } from 'react-router-dom';
|
2025-03-05 17:10:26 +01:00
|
|
|
import { Comment, useAuthorAvatar, useEditedComment } from '@plebbit/plebbit-react-hooks';
|
|
|
|
|
import useSubplebbitsStore from '@plebbit/plebbit-react-hooks/dist/stores/subplebbits';
|
2025-05-12 23:54:44 +02:00
|
|
|
import Plebbit from '@plebbit/plebbit-js';
|
2024-06-11 15:49:26 +02:00
|
|
|
import styles from '../../views/post/post.module.css';
|
2025-02-22 22:22:42 +01:00
|
|
|
import { shouldShowSnow } from '../../lib/snow';
|
2024-12-05 15:37:23 +01:00
|
|
|
import { getHasThumbnail } from '../../lib/utils/media-utils';
|
2024-08-13 18:27:56 +02:00
|
|
|
import { getTextColorForBackground, hashStringToColor } from '../../lib/utils/post-utils';
|
2024-06-27 11:03:58 +02:00
|
|
|
import { getFormattedDate, getFormattedTimeAgo } from '../../lib/utils/time-utils';
|
2024-06-11 15:49:26 +02:00
|
|
|
import { isAllView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
2025-11-07 12:50:58 +01:00
|
|
|
import { useDefaultSubplebbits } from '../../hooks/use-default-subplebbits';
|
2025-11-14 14:52:13 +01:00
|
|
|
import { getBoardPath } from '../../lib/utils/route-utils';
|
2024-09-03 10:14:15 +02:00
|
|
|
import useAvatarVisibilityStore from '../../stores/use-avatar-visibility-store';
|
2024-06-28 22:09:11 +02:00
|
|
|
import useAuthorAddressClick from '../../hooks/use-author-address-click';
|
2024-12-05 15:37:23 +01:00
|
|
|
import { useCommentMediaInfo } from '../../hooks/use-comment-media-info';
|
2024-06-11 15:49:26 +02:00
|
|
|
import useCountLinksInReplies from '../../hooks/use-count-links-in-replies';
|
2024-06-14 12:51:43 +02:00
|
|
|
import useHide from '../../hooks/use-hide';
|
2024-06-11 15:49:26 +02:00
|
|
|
import useReplies from '../../hooks/use-replies';
|
|
|
|
|
import useStateString from '../../hooks/use-state-string';
|
2025-02-22 22:22:42 +01:00
|
|
|
import CommentContent from '../comment-content';
|
2024-06-11 15:49:26 +02:00
|
|
|
import CommentMedia from '../comment-media';
|
|
|
|
|
import LoadingEllipsis from '../loading-ellipsis';
|
2024-05-28 19:03:43 +02:00
|
|
|
import PostMenuMobile from './post-menu-mobile';
|
2024-06-27 11:03:58 +02:00
|
|
|
import ReplyQuotePreview from '../reply-quote-preview';
|
|
|
|
|
import Tooltip from '../tooltip';
|
2024-06-11 15:49:26 +02:00
|
|
|
import { PostProps } from '../../views/post/post';
|
2024-05-16 23:05:00 +02:00
|
|
|
import _ from 'lodash';
|
2025-03-05 12:01:48 +01:00
|
|
|
import useReplyModalStore from '../../stores/use-reply-modal-store';
|
2024-05-16 23:05:00 +02:00
|
|
|
|
2025-03-05 12:01:48 +01:00
|
|
|
const PostInfoAndMedia = ({ post, postReplyCount = 0, roles }: PostProps) => {
|
2024-05-16 23:05:00 +02:00
|
|
|
const { t } = useTranslation();
|
2025-11-07 12:50:58 +01:00
|
|
|
const defaultSubplebbits = useDefaultSubplebbits();
|
2025-03-03 23:47:33 +01:00
|
|
|
const {
|
|
|
|
|
author,
|
|
|
|
|
cid,
|
|
|
|
|
deleted,
|
|
|
|
|
link,
|
|
|
|
|
linkHeight,
|
|
|
|
|
linkWidth,
|
|
|
|
|
locked,
|
|
|
|
|
parentCid,
|
|
|
|
|
pinned,
|
|
|
|
|
postCid,
|
|
|
|
|
reason,
|
|
|
|
|
removed,
|
|
|
|
|
shortCid,
|
|
|
|
|
state,
|
|
|
|
|
subplebbitAddress,
|
|
|
|
|
timestamp,
|
|
|
|
|
thumbnailUrl,
|
|
|
|
|
} = post || {};
|
2025-11-07 18:34:06 +01:00
|
|
|
const boardPath = subplebbitAddress ? getBoardPath(subplebbitAddress, defaultSubplebbits) : undefined;
|
2024-12-05 15:37:23 +01:00
|
|
|
const isReply = parentCid;
|
2024-06-27 11:03:58 +02:00
|
|
|
const title = post?.title?.trim();
|
2024-05-16 23:05:00 +02:00
|
|
|
const { isDescription, isRules } = post || {}; // custom properties, not from api
|
2024-06-27 11:03:58 +02:00
|
|
|
const { address, shortAddress } = author || {};
|
|
|
|
|
const displayName = author?.displayName?.trim();
|
|
|
|
|
const authorRole = roles?.[address]?.role;
|
2024-07-12 22:06:14 +02:00
|
|
|
const { imageUrl: avatarImageUrl } = useAuthorAvatar({ author });
|
2024-09-03 10:14:15 +02:00
|
|
|
const { hideAvatars } = useAvatarVisibilityStore();
|
2024-05-16 23:05:00 +02:00
|
|
|
|
2024-06-29 11:55:36 +02:00
|
|
|
const params = useParams();
|
2024-05-17 15:29:03 +02:00
|
|
|
const location = useLocation();
|
2024-10-29 17:40:09 +01:00
|
|
|
const isInAllView = isAllView(location.pathname);
|
2024-06-29 11:55:36 +02:00
|
|
|
const isInPostPageView = isPostPageView(location.pathname, params);
|
|
|
|
|
const isInSubscriptionsView = isSubscriptionsView(location.pathname, params);
|
2024-05-17 15:29:03 +02:00
|
|
|
|
2025-03-03 23:47:33 +01:00
|
|
|
const commentMediaInfo = useCommentMediaInfo(link, thumbnailUrl, linkWidth, linkHeight);
|
2024-05-16 23:05:00 +02:00
|
|
|
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
|
|
|
|
|
|
|
|
|
const stateString = useStateString(post);
|
|
|
|
|
|
2024-06-28 22:09:11 +02:00
|
|
|
const handleUserAddressClick = useAuthorAddressClick();
|
2024-07-01 10:26:38 +02:00
|
|
|
const numberOfPostsByAuthor = document.querySelectorAll(`[data-author-address="${shortAddress}"][data-post-cid="${postCid}"]`).length;
|
2024-06-28 22:09:11 +02:00
|
|
|
|
2024-09-20 16:16:09 +02:00
|
|
|
const userID = address && Plebbit.getShortAddress(address);
|
2024-09-19 17:33:00 +02:00
|
|
|
const userIDBackgroundColor = hashStringToColor(userID);
|
2024-08-13 18:27:56 +02:00
|
|
|
const userIDTextColor = getTextColorForBackground(userIDBackgroundColor);
|
|
|
|
|
|
2024-09-18 17:08:42 +02:00
|
|
|
const { hidden } = useHide(post);
|
|
|
|
|
|
2025-03-05 12:01:48 +01:00
|
|
|
const { openReplyModal } = useReplyModalStore();
|
|
|
|
|
|
2025-03-02 12:10:16 +01:00
|
|
|
const onReplyModalClick = () => {
|
|
|
|
|
deleted
|
|
|
|
|
? isReply
|
|
|
|
|
? alert(t('this_reply_was_deleted'))
|
|
|
|
|
: alert(t('this_thread_was_deleted'))
|
|
|
|
|
: removed
|
|
|
|
|
? isReply
|
|
|
|
|
? alert(t('this_reply_was_removed'))
|
|
|
|
|
: alert(t('this_thread_was_removed'))
|
|
|
|
|
: openReplyModal && openReplyModal(cid, postCid, subplebbitAddress);
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-16 23:05:00 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className={styles.postInfo}>
|
2024-05-28 19:03:43 +02:00
|
|
|
<PostMenuMobile post={post} />
|
2024-09-21 13:01:23 +02:00
|
|
|
<span className={(hidden || ((removed || deleted) && !reason)) && parentCid ? styles.postDesktopHidden : ''}>
|
2024-09-18 17:08:42 +02:00
|
|
|
<span className={styles.nameBlock}>
|
|
|
|
|
<span className={`${styles.name} ${(isDescription || isRules || authorRole) && !(deleted || removed) && styles.capcodeMod}`}>
|
2024-08-25 18:15:27 +02:00
|
|
|
{removed ? (
|
2024-09-18 17:08:42 +02:00
|
|
|
_.capitalize(t('removed'))
|
2024-08-25 18:15:27 +02:00
|
|
|
) : deleted ? (
|
2024-09-18 17:08:42 +02:00
|
|
|
_.capitalize(t('deleted'))
|
|
|
|
|
) : displayName ? (
|
|
|
|
|
displayName.length <= 20 ? (
|
|
|
|
|
displayName
|
|
|
|
|
) : (
|
|
|
|
|
<Tooltip
|
|
|
|
|
children={displayName.slice(0, 20) + '(...)'}
|
|
|
|
|
content={displayName.length < 1000 ? displayName : displayName.slice(0, 1000) + `... ${t('display_name_too_long')}`}
|
|
|
|
|
/>
|
|
|
|
|
)
|
2024-08-25 18:15:27 +02:00
|
|
|
) : (
|
2024-09-18 17:08:42 +02:00
|
|
|
_.capitalize(t('anonymous'))
|
2024-08-25 18:15:27 +02:00
|
|
|
)}
|
2024-09-18 17:08:42 +02:00
|
|
|
{!(deleted || removed) && <span className='capitalize'>{authorRole && ` ## Board ${authorRole}`} </span>}
|
2024-05-16 23:05:00 +02:00
|
|
|
</span>
|
2024-09-18 17:08:42 +02:00
|
|
|
{!(isDescription || isRules) && (
|
2024-08-29 12:56:09 +02:00
|
|
|
<>
|
2025-10-16 23:37:58 +02:00
|
|
|
{author?.avatar && !(deleted || removed) && !hideAvatars && avatarImageUrl ? (
|
2024-09-18 17:08:42 +02:00
|
|
|
<span className={styles.authorAvatar}>
|
|
|
|
|
<img src={avatarImageUrl} alt='' />
|
|
|
|
|
</span>
|
2025-10-16 23:37:58 +02:00
|
|
|
) : null}
|
2024-09-18 17:08:42 +02:00
|
|
|
(ID: {''}
|
|
|
|
|
{removed ? (
|
|
|
|
|
_.lowerCase(t('removed'))
|
|
|
|
|
) : deleted ? (
|
|
|
|
|
_.lowerCase(t('deleted'))
|
|
|
|
|
) : (
|
|
|
|
|
<Tooltip
|
|
|
|
|
children={
|
|
|
|
|
<span
|
|
|
|
|
title={t('highlight_posts')}
|
|
|
|
|
className={styles.userAddress}
|
2024-09-19 17:33:00 +02:00
|
|
|
onClick={() => handleUserAddressClick(userID, postCid)}
|
2024-09-18 17:08:42 +02:00
|
|
|
style={{ backgroundColor: userIDBackgroundColor, color: userIDTextColor }}
|
|
|
|
|
>
|
2024-09-19 17:33:00 +02:00
|
|
|
{userID}
|
2024-09-18 17:08:42 +02:00
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
content={`${numberOfPostsByAuthor === 1 ? t('1_post_by_this_id') : t('x_posts_by_this_id', { number: numberOfPostsByAuthor })}`}
|
|
|
|
|
showTooltip={isInPostPageView || postReplyCount < 6}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
){' '}
|
2024-08-29 12:56:09 +02:00
|
|
|
</>
|
2024-09-18 17:08:42 +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>
|
|
|
|
|
)}
|
|
|
|
|
{title && (
|
|
|
|
|
<span className={styles.subjectWrapper}>
|
|
|
|
|
{title.length <= 30 ? (
|
|
|
|
|
<span className={styles.subject}>{title}</span>
|
|
|
|
|
) : (
|
|
|
|
|
<Tooltip
|
|
|
|
|
children={<span className={styles.subject}>{title.slice(0, 30) + '(...)'}</span>}
|
|
|
|
|
content={title.length < 1000 ? title : title.slice(0, 1000) + `... ${t('title_too_long')}`}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.dateTimePostNum}>
|
2025-11-07 18:34:06 +01:00
|
|
|
{subplebbitAddress && (isInAllView || isInSubscriptionsView) && !isReply && boardPath && (
|
2024-09-18 17:08:42 +02:00
|
|
|
<div className={styles.postNumLink}>
|
|
|
|
|
{' '}
|
2025-11-14 14:52:13 +01:00
|
|
|
<Link to={`/${boardPath}`}>Board: {boardPath}</Link>
|
2024-09-18 17:08:42 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<Tooltip children={<span>{getFormattedDate(timestamp)}</span>} content={getFormattedTimeAgo(timestamp)} />{' '}
|
|
|
|
|
{!(isDescription || isRules) &&
|
|
|
|
|
(cid ? (
|
|
|
|
|
<span className={styles.postNumLink}>
|
2025-11-07 18:34:06 +01:00
|
|
|
<Link
|
|
|
|
|
to={boardPath ? `/${boardPath}/thread/${cid}` : `/thread/${cid}`}
|
|
|
|
|
className={styles.linkToPost}
|
|
|
|
|
title={t('link_to_post')}
|
|
|
|
|
onClick={(e) => !cid && e.preventDefault()}
|
|
|
|
|
>
|
2025-11-08 21:19:36 +01:00
|
|
|
CID:
|
2024-09-18 17:08:42 +02:00
|
|
|
</Link>
|
2025-03-02 12:10:16 +01:00
|
|
|
<span className={styles.replyToPost} title={t('reply_to_post')} onMouseDown={onReplyModalClick}>
|
2024-09-18 17:08:42 +02:00
|
|
|
{shortCid.slice(0, -4)}
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
2025-11-08 21:19:36 +01:00
|
|
|
<span>CID:</span>
|
2024-09-18 17:08:42 +02:00
|
|
|
<span className={styles.pendingCid}>
|
|
|
|
|
{state === 'failed' || stateString === 'Failed' ? _.capitalize(t('failed')) : state === 'pending' ? _.capitalize(t('pending')) : ''}
|
|
|
|
|
</span>
|
|
|
|
|
</>
|
|
|
|
|
))}
|
|
|
|
|
</span>
|
2024-05-16 23:05:00 +02:00
|
|
|
</span>
|
|
|
|
|
</div>
|
2025-03-03 23:47:33 +01:00
|
|
|
{(hasThumbnail || link) && !(deleted || removed) && <PostMediaContent key={cid} post={post} link={link} />}
|
2024-05-16 23:05:00 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-03 23:47:33 +01:00
|
|
|
const PostMediaContent = ({ post, link }: { post: any; link: string }) => {
|
2024-11-21 17:23:14 +01:00
|
|
|
const [showThumbnail, setShowThumbnail] = useState(true);
|
2024-11-29 21:53:53 +01:00
|
|
|
const { isDescription, isRules } = post || {}; // custom properties, not from api
|
2025-03-03 23:47:33 +01:00
|
|
|
const { thumbnailUrl, linkWidth, linkHeight, spoiler, deleted, removed, parentCid } = post || {};
|
|
|
|
|
const commentMediaInfo = useCommentMediaInfo(link, thumbnailUrl, linkWidth, linkHeight);
|
2024-11-21 17:23:14 +01:00
|
|
|
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
|
|
|
|
|
2024-11-29 21:53:53 +01:00
|
|
|
return (
|
|
|
|
|
hasThumbnail && (
|
|
|
|
|
<CommentMedia
|
|
|
|
|
commentMediaInfo={commentMediaInfo}
|
2025-03-03 23:47:33 +01:00
|
|
|
deleted={deleted}
|
|
|
|
|
isDescription={isDescription}
|
|
|
|
|
isRules={isRules}
|
|
|
|
|
removed={removed}
|
|
|
|
|
linkHeight={linkHeight}
|
|
|
|
|
linkWidth={linkWidth}
|
2024-11-29 21:53:53 +01:00
|
|
|
showThumbnail={showThumbnail}
|
|
|
|
|
setShowThumbnail={setShowThumbnail}
|
|
|
|
|
isOutOfFeed={isDescription || isRules}
|
2025-03-03 23:47:33 +01:00
|
|
|
parentCid={parentCid}
|
|
|
|
|
spoiler={spoiler}
|
2024-11-29 21:53:53 +01:00
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
);
|
2024-11-21 17:23:14 +01:00
|
|
|
};
|
|
|
|
|
|
2025-03-05 21:38:01 +01:00
|
|
|
const ReplyBacklinks = ({ post }: PostProps) => {
|
2024-08-31 14:57:11 +02:00
|
|
|
const { cid, parentCid } = post || {};
|
2024-06-04 17:48:53 +02:00
|
|
|
const replies = useReplies(post);
|
|
|
|
|
|
|
|
|
|
return (
|
2024-08-31 14:57:11 +02:00
|
|
|
cid &&
|
2024-06-04 17:48:53 +02:00
|
|
|
parentCid &&
|
2024-09-03 10:23:50 +02:00
|
|
|
replies.length > 0 && (
|
2024-06-04 17:48:53 +02:00
|
|
|
<div className={styles.mobileReplyBacklinks}>
|
2024-08-31 14:57:11 +02:00
|
|
|
{replies.map(
|
2024-12-01 15:08:40 +01:00
|
|
|
(reply: Comment, index: number) =>
|
|
|
|
|
reply?.parentCid === cid &&
|
|
|
|
|
reply?.cid &&
|
2025-03-05 21:38:01 +01:00
|
|
|
!(reply?.deleted || reply?.removed) && <ReplyQuotePreview key={index} isBacklinkReply={true} backlinkReply={reply} />,
|
2024-08-31 14:57:11 +02:00
|
|
|
)}
|
2024-06-04 17:48:53 +02:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-05 21:38:01 +01:00
|
|
|
const Reply = ({ postReplyCount, reply, roles }: PostProps) => {
|
2024-06-21 22:02:56 +02:00
|
|
|
let post = reply;
|
|
|
|
|
// handle pending mod or author edit
|
|
|
|
|
const { editedComment } = useEditedComment({ comment: reply });
|
|
|
|
|
if (editedComment) {
|
|
|
|
|
post = editedComment;
|
|
|
|
|
}
|
2024-09-21 12:59:16 +02:00
|
|
|
const { author, cid, deleted, postCid, reason, removed, subplebbitAddress } = post || {};
|
2025-11-07 12:50:58 +01:00
|
|
|
const defaultSubplebbits = useDefaultSubplebbits();
|
2025-11-07 18:34:06 +01:00
|
|
|
const boardPath = subplebbitAddress ? getBoardPath(subplebbitAddress, defaultSubplebbits) : undefined;
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const route = boardPath ? `/${boardPath}/thread/${cid}` : `/thread/${cid}`;
|
|
|
|
|
const isRouteLinkToReply = cid ? location.pathname.startsWith(route) : false;
|
2024-06-14 12:51:43 +02:00
|
|
|
const { hidden } = useHide({ cid });
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={styles.replyMobile}>
|
|
|
|
|
<div className={styles.reply}>
|
2024-06-28 22:09:11 +02:00
|
|
|
<div
|
2024-09-18 17:08:42 +02:00
|
|
|
className={`${styles.replyContainer} ${isRouteLinkToReply && styles.highlight}`}
|
2024-06-29 11:55:36 +02:00
|
|
|
data-cid={cid}
|
2024-07-01 10:26:38 +02:00
|
|
|
data-author-address={author?.shortAddress}
|
|
|
|
|
data-post-cid={postCid}
|
2024-06-28 22:09:11 +02:00
|
|
|
>
|
2025-03-05 12:01:48 +01:00
|
|
|
<PostInfoAndMedia post={post} postReplyCount={postReplyCount} roles={roles} />
|
2025-03-05 21:38:01 +01:00
|
|
|
{!hidden && (!(removed || deleted) || ((removed || deleted) && reason)) && <CommentContent comment={post} />}
|
2024-06-14 12:51:43 +02:00
|
|
|
<ReplyBacklinks post={reply} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-05 21:38:01 +01:00
|
|
|
const PostMobile = ({ post, roles, showAllReplies, showReplies = true }: PostProps) => {
|
2024-05-16 23:05:00 +02:00
|
|
|
const { t } = useTranslation();
|
2024-09-21 12:50:24 +02:00
|
|
|
const { author, cid, pinned, postCid, replyCount, state, subplebbitAddress } = post || {};
|
2024-05-16 23:05:00 +02:00
|
|
|
const { isDescription, isRules } = post || {}; // custom properties, not from api
|
2024-05-17 15:29:03 +02:00
|
|
|
const params = useParams();
|
|
|
|
|
const location = useLocation();
|
2024-10-29 17:40:09 +01:00
|
|
|
const isInAllView = isAllView(location.pathname);
|
2024-05-17 15:29:03 +02:00
|
|
|
const isInPendingPostView = isPendingPostView(location.pathname, params);
|
|
|
|
|
const isInPostView = isPostPageView(location.pathname, params);
|
2025-11-07 12:50:58 +01:00
|
|
|
const defaultSubplebbits = useDefaultSubplebbits();
|
2025-11-07 18:34:06 +01:00
|
|
|
const boardPath = subplebbitAddress ? getBoardPath(subplebbitAddress, defaultSubplebbits) : undefined;
|
2024-05-16 23:05:00 +02:00
|
|
|
const linksCount = useCountLinksInReplies(post);
|
2025-03-05 21:38:01 +01:00
|
|
|
const replies = useReplies(post);
|
2024-05-16 23:05:00 +02:00
|
|
|
|
2024-06-14 12:51:43 +02:00
|
|
|
const isInPostPageView = isPostPageView(location.pathname, params);
|
|
|
|
|
const { hidden, unhide } = useHide({ cid });
|
|
|
|
|
|
2025-02-20 13:29:24 +01:00
|
|
|
const stateString = useStateString(post) || t('loading_post');
|
2024-07-21 12:17:40 +02:00
|
|
|
|
2025-03-05 17:10:26 +01:00
|
|
|
const subplebbit = useSubplebbitsStore((state) => state.subplebbits[subplebbitAddress]);
|
2024-09-15 21:27:32 +02:00
|
|
|
const showRules = isDescription && subplebbit?.rules && subplebbit?.rules.length > 0;
|
|
|
|
|
const subplebbitRulesReply = {
|
|
|
|
|
isRules: true,
|
|
|
|
|
subplebbitAddress,
|
|
|
|
|
timestamp: subplebbit?.createdAt,
|
|
|
|
|
author: { displayName: `## ${t('board_mods')}` },
|
|
|
|
|
content: `${subplebbit?.rules?.map((rule: string, index: number) => `${index + 1}. ${rule}`).join('\n')}`,
|
|
|
|
|
replyCount: 0,
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-16 23:05:00 +02:00
|
|
|
return (
|
2024-06-14 12:51:43 +02:00
|
|
|
<>
|
|
|
|
|
{hidden && !isInPostPageView ? (
|
|
|
|
|
<>
|
|
|
|
|
<hr className={styles.unhideButtonHr} />
|
|
|
|
|
<span className={styles.mobileUnhideButton}>
|
|
|
|
|
<span className='button' onClick={unhide}>
|
|
|
|
|
Show Hidden Thread
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<div className={styles.postMobile}>
|
|
|
|
|
{showReplies && (
|
|
|
|
|
<div className={styles.hrWrapper}>
|
|
|
|
|
<hr />
|
2024-05-16 23:05:00 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
2024-06-14 12:51:43 +02:00
|
|
|
<div className={showReplies ? styles.thread : styles.quotePreview}>
|
|
|
|
|
<div className={styles.postContainer}>
|
2024-12-24 17:13:12 +01:00
|
|
|
<div
|
|
|
|
|
className={`${styles.postOp} ${shouldShowSnow() ? styles.xmasHatWrapper : ''}`}
|
|
|
|
|
data-cid={cid}
|
|
|
|
|
data-author-address={author?.shortAddress}
|
|
|
|
|
data-post-cid={postCid}
|
|
|
|
|
>
|
2025-05-22 13:15:40 +02:00
|
|
|
{shouldShowSnow() && <img src='assets/xmashat.gif' className={styles.xmasHat} alt='' />}
|
2025-03-05 12:01:48 +01:00
|
|
|
<PostInfoAndMedia post={post} postReplyCount={replyCount} roles={roles} />
|
2025-03-05 21:38:01 +01:00
|
|
|
<CommentContent comment={post} />
|
2024-05-16 23:05:00 +02:00
|
|
|
</div>
|
2024-06-14 12:51:43 +02:00
|
|
|
{!isInPostView && !isInPendingPostView && showReplies && (
|
|
|
|
|
<div className={styles.postLink}>
|
|
|
|
|
<span className={styles.info}>
|
|
|
|
|
{replyCount > 0 && `${replyCount} Replies`}
|
|
|
|
|
{linksCount > 0 && ` / ${linksCount} Links`}
|
|
|
|
|
</span>
|
|
|
|
|
<Link
|
2025-11-07 18:34:06 +01:00
|
|
|
to={
|
|
|
|
|
isInAllView && isDescription
|
|
|
|
|
? '/all/description'
|
|
|
|
|
: boardPath
|
|
|
|
|
? `/${boardPath}/${isDescription ? 'description' : isRules ? 'rules' : `thread/${cid}`}`
|
|
|
|
|
: `/${isDescription ? 'description' : isRules ? 'rules' : `thread/${cid}`}`
|
|
|
|
|
}
|
2024-06-14 12:51:43 +02:00
|
|
|
className='button'
|
|
|
|
|
>
|
|
|
|
|
{t('view_thread')}
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
{!(pinned && !isInPostView) &&
|
|
|
|
|
!isInPendingPostView &&
|
|
|
|
|
replies &&
|
|
|
|
|
showReplies &&
|
2025-06-03 22:18:32 +02:00
|
|
|
(showAllReplies ? replies : replies.slice(-5))
|
|
|
|
|
// Don't render deleted replies that have no children (replyCount = 0)
|
|
|
|
|
.filter((reply) => !(reply.deleted && (reply.replyCount === 0 || !reply.replyCount)))
|
|
|
|
|
.map((reply, index) => (
|
|
|
|
|
<div key={index} className={styles.replyContainer}>
|
|
|
|
|
<Reply postReplyCount={replyCount} reply={reply} roles={roles} />
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
2024-09-15 21:27:32 +02:00
|
|
|
{showRules && (
|
|
|
|
|
<div className={styles.replyContainer}>
|
|
|
|
|
<Reply reply={subplebbitRulesReply} />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-06-14 12:51:43 +02:00
|
|
|
</div>
|
2024-07-22 12:29:32 +02:00
|
|
|
{!isInPendingPostView &&
|
2025-02-24 22:59:17 +01:00
|
|
|
(!isDescription || (isDescription && !subplebbit?.updatedAt)) &&
|
2025-02-23 16:24:31 +01:00
|
|
|
!isRules &&
|
|
|
|
|
stateString &&
|
|
|
|
|
stateString !== 'Failed' &&
|
|
|
|
|
state !== 'succeeded' &&
|
|
|
|
|
isInPostPageView &&
|
|
|
|
|
!(!showReplies && !showAllReplies) ? (
|
|
|
|
|
<div className={styles.stateString}>
|
|
|
|
|
<LoadingEllipsis string={stateString} />
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
state === 'failed' && <span className={styles.error}>{t('failed')}</span>
|
|
|
|
|
)}
|
2024-06-14 12:51:43 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
2024-05-16 23:05:00 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default PostMobile;
|