import { useEffect, useRef, useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import { Link, useLocation, useParams } from 'react-router-dom'; import { Comment, useAccount, useComment, useEditedComment } from '@plebbit/plebbit-react-hooks'; import Plebbit from '@plebbit/plebbit-js/dist/browser/index.js'; import styles from '../../views/post/post.module.css'; import { getCommentMediaInfo, getHasThumbnail } from '../../lib/utils/media-utils'; import { getFormattedDate } from '../../lib/utils/time-utils'; import { isAllView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils'; import useCountLinksInReplies from '../../hooks/use-count-links-in-replies'; import useHide from '../../hooks/use-hide'; import useReplies from '../../hooks/use-replies'; import useStateString from '../../hooks/use-state-string'; import CommentMedia from '../comment-media'; import LoadingEllipsis from '../loading-ellipsis'; import Markdown from '../markdown'; import ReplyQuotePreview from '../reply-quote-preview'; import PostMenuMobile from './post-menu-mobile'; import { PostProps } from '../../views/post/post'; import Timestamp from '../timestamp'; import _ from 'lodash'; const PostInfoAndMedia = ({ openReplyModal, post, roles }: PostProps) => { const { t } = useTranslation(); const { author, cid, link, locked, parentCid, pinned, shortCid, state, subplebbitAddress, timestamp, title } = post || {}; const { isDescription, isRules } = post || {}; // custom properties, not from api const { address, displayName, shortAddress } = author || {}; const location = useLocation(); const isInAllView = isAllView(location.pathname, useParams()); const isInSubscriptionsView = isSubscriptionsView(location.pathname, useParams()); const authorRole = roles?.[address]?.role; const shortDisplayName = displayName?.trim().length > 20 ? displayName?.trim().slice(0, 20).trim() + '...' : displayName?.trim(); const displayTitle = title && title.length > 30 ? title?.slice(0, 30) + '(...)' : title; const commentMediaInfo = getCommentMediaInfo(post); const hasThumbnail = getHasThumbnail(commentMediaInfo, link); const [showThumbnail, setShowThumbnail] = useState(true); const isReply = parentCid; // pending reply by account is not yet published const account = useAccount(); const accountShortAddress = account?.author?.shortAddress; const stateString = useStateString(post); return ( <>
{isReply && !(removed || deleted) && isReplyingToReply &&) ); }; const Reply = ({ openReplyModal, reply, roles }: PostProps) => { let post = reply; // handle pending mod or author edit const { editedComment } = useEditedComment({ comment: reply }); if (editedComment) { post = editedComment; } const { cid, content, subplebbitAddress } = post || {}; const isRouteLinkToReply = useLocation().pathname.startsWith(`/p/${subplebbitAddress}/c/${cid}`); const { hidden } = useHide({ cid }); return (} {removed ? ( ({t('this_post_was_removed')}) ) : deleted ? ( {t('user_deleted_this_post')} ) : ( <> {!showOriginal && } {edit && original?.content !== post?.content && ( {showOriginal && }
{t('comment_edited_at_timestamp', { timestamp: getFormattedDate(edit?.timestamp), interpolation: { escapeValue: false } })}{' '} {reason && <>{t('reason_reason', { reason: reason, interpolation: { escapeValue: false } })} >} {showOriginal ? (setShowOriginal(!showOriginal)} /> }} /> ) : ( )} > )} {(removed || deleted) && reason && (setShowOriginal(!showOriginal)} /> }} /> )}
reason: {reason} )} {!isReply && content.length > 1000 && !isInPostView && (
}} /> )} {!cid && state === 'pending' && stateString !== 'Failed' && ( <>
{loadingString} > )}