2024-10-13 12:58:29 +02:00
|
|
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
2024-05-16 23:05:00 +02:00
|
|
|
import { Trans, useTranslation } from 'react-i18next';
|
2024-06-05 22:18:45 +02:00
|
|
|
import { Link, useLocation, useParams } from 'react-router-dom';
|
2024-09-19 17:33:00 +02:00
|
|
|
import { Comment, useAuthorAvatar, useComment, useEditedComment, useSubplebbit } from '@plebbit/plebbit-react-hooks';
|
2024-05-16 23:05:00 +02:00
|
|
|
import Plebbit from '@plebbit/plebbit-js/dist/browser/index.js';
|
2024-06-11 15:49:26 +02:00
|
|
|
import styles from '../../views/post/post.module.css';
|
2024-10-11 21:38:16 +02:00
|
|
|
import { fetchWebpageThumbnailIfNeeded, getCommentMediaInfo, getDisplayMediaInfoType, getHasThumbnail, getMediaDimensions } from '../../lib/utils/media-utils';
|
2024-08-13 18:27:56 +02:00
|
|
|
import { hashStringToColor, getTextColorForBackground } 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 { isValidURL } from '../../lib/utils/url-utils';
|
|
|
|
|
import { isAllView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-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-06-13 17:50:05 +02:00
|
|
|
import useCountLinksInReplies from '../../hooks/use-count-links-in-replies';
|
2024-09-03 10:14:15 +02:00
|
|
|
import useFetchGifFirstFrame from '../../hooks/use-fetch-gif-first-frame';
|
2024-06-13 17:50:05 +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';
|
|
|
|
|
import CommentMedia from '../comment-media';
|
2024-06-27 11:03:58 +02:00
|
|
|
import EditMenu from '../edit-menu/edit-menu';
|
2024-06-11 15:49:26 +02:00
|
|
|
import { canEmbed } from '../embed';
|
|
|
|
|
import LoadingEllipsis from '../loading-ellipsis';
|
|
|
|
|
import Markdown from '../markdown';
|
|
|
|
|
import PostMenuDesktop from './post-menu-desktop';
|
2024-06-06 17:28:16 +02:00
|
|
|
import ReplyQuotePreview from '../reply-quote-preview';
|
2024-06-27 11:03:58 +02:00
|
|
|
import Tooltip from '../tooltip';
|
2024-06-11 15:49:26 +02:00
|
|
|
import { PostProps } from '../../views/post/post';
|
2024-07-01 10:26:38 +02:00
|
|
|
import { create } from 'zustand';
|
2024-05-16 23:05:00 +02:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
|
2024-07-01 10:26:38 +02:00
|
|
|
interface ShowOmittedRepliesState {
|
2024-07-02 08:55:55 +02:00
|
|
|
showOmittedReplies: Record<string, boolean>;
|
|
|
|
|
setShowOmittedReplies: (cid: string, showOmittedReplies: boolean) => void;
|
2024-07-01 10:26:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const useShowOmittedReplies = create<ShowOmittedRepliesState>((set) => ({
|
2024-07-02 08:55:55 +02:00
|
|
|
showOmittedReplies: {},
|
|
|
|
|
setShowOmittedReplies: (cid, showOmittedReplies) =>
|
|
|
|
|
set((state) => ({
|
|
|
|
|
showOmittedReplies: {
|
|
|
|
|
...state.showOmittedReplies,
|
|
|
|
|
[cid]: showOmittedReplies,
|
|
|
|
|
},
|
|
|
|
|
})),
|
2024-07-01 10:26:38 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const PostInfo = ({ openReplyModal, post, postReplyCount = 0, roles, isHidden }: PostProps) => {
|
2024-05-16 23:05:00 +02:00
|
|
|
const { t } = useTranslation();
|
2024-09-21 12:59:16 +02:00
|
|
|
const { author, cid, deleted, locked, pinned, parentCid, postCid, reason, removed, shortCid, state, subplebbitAddress, timestamp } = post || {};
|
2024-06-27 11:03:58 +02:00
|
|
|
const title = post?.title?.trim();
|
2024-06-04 17:48:53 +02:00
|
|
|
const replies = useReplies(post);
|
2024-06-27 11:03:58 +02:00
|
|
|
const { address, shortAddress } = author || {};
|
|
|
|
|
const displayName = author?.displayName?.trim();
|
|
|
|
|
const authorRole = roles?.[address]?.role;
|
2024-05-16 23:05:00 +02:00
|
|
|
const { isDescription, isRules } = post || {}; // custom properties, not from api
|
|
|
|
|
const stateString = useStateString(post);
|
|
|
|
|
const isReply = parentCid;
|
2024-07-01 10:26:38 +02:00
|
|
|
const { showOmittedReplies } = useShowOmittedReplies();
|
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-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-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
|
|
|
|
2024-09-19 17:33:00 +02:00
|
|
|
const userID = address && Plebbit.getShortAddress(address);
|
|
|
|
|
const userIDBackgroundColor = hashStringToColor(userID);
|
|
|
|
|
const userIDTextColor = getTextColorForBackground(userIDBackgroundColor);
|
2024-06-04 16:06:28 +02:00
|
|
|
|
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-18 17:08:42 +02:00
|
|
|
const { hidden } = useHide(post);
|
|
|
|
|
|
2024-05-16 23:05:00 +02:00
|
|
|
return (
|
|
|
|
|
<div className={styles.postInfo}>
|
2024-09-04 16:15:47 +02:00
|
|
|
{!isHidden && <EditMenu 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
|
|
|
{title &&
|
|
|
|
|
(title.length <= 75 ? (
|
|
|
|
|
<span className={styles.subject}>{title} </span>
|
2024-06-27 11:03:58 +02:00
|
|
|
) : (
|
2024-09-18 17:08:42 +02:00
|
|
|
<Tooltip
|
|
|
|
|
children={<span className={styles.subject}>{title.slice(0, 75) + '(...)'} </span>}
|
|
|
|
|
content={title.length < 1000 ? title : title.slice(0, 1000) + `... ${t('title_too_long')}`}
|
|
|
|
|
/>
|
2024-08-29 12:56:09 +02:00
|
|
|
))}
|
2024-09-18 17:08:42 +02:00
|
|
|
<span className={styles.nameBlock}>
|
|
|
|
|
<span className={`${styles.name} ${(isDescription || isRules || authorRole) && !(deleted || removed) && styles.capcodeMod}`}>
|
|
|
|
|
{deleted ? (
|
|
|
|
|
_.capitalize(t('deleted'))
|
|
|
|
|
) : removed ? (
|
|
|
|
|
_.capitalize(t('removed'))
|
|
|
|
|
) : 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')}`}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
) : (
|
|
|
|
|
_.capitalize(t('anonymous'))
|
|
|
|
|
)}
|
|
|
|
|
{!(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) && (
|
|
|
|
|
<>
|
|
|
|
|
{author?.avatar && !(deleted || removed) && !hideAvatars ? (
|
|
|
|
|
<span className={styles.authorAvatar}>
|
|
|
|
|
<img src={avatarImageUrl} alt='' />
|
|
|
|
|
</span>
|
|
|
|
|
) : (
|
|
|
|
|
' '
|
|
|
|
|
)}
|
|
|
|
|
(ID:{' '}
|
|
|
|
|
{deleted ? (
|
|
|
|
|
t('deleted')
|
|
|
|
|
) : removed ? (
|
|
|
|
|
t('removed')
|
|
|
|
|
) : (
|
|
|
|
|
<Tooltip
|
|
|
|
|
children={
|
|
|
|
|
<span
|
|
|
|
|
title={t('highlight_posts')}
|
|
|
|
|
className={styles.userAddress}
|
|
|
|
|
onClick={() => handleUserAddressClick(userID, postCid)}
|
|
|
|
|
style={{ backgroundColor: userIDBackgroundColor, color: userIDTextColor }}
|
|
|
|
|
>
|
|
|
|
|
{userID}
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
content={`${numberOfPostsByAuthor === 1 ? t('1_post_by_this_id') : t('x_posts_by_this_id', { number: numberOfPostsByAuthor })}`}
|
|
|
|
|
showTooltip={isInPostPageView || showOmittedReplies[postCid] || (postReplyCount < 6 && !pinned)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
){' '}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.dateTime}>
|
|
|
|
|
<Tooltip children={<span>{getFormattedDate(timestamp)}</span>} content={getFormattedTimeAgo(timestamp)} />
|
|
|
|
|
{isDescription || isRules ? '' : ' '}
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.postNum}>
|
|
|
|
|
{subplebbitAddress && (isInAllView || isInSubscriptionsView) && !isReply && (
|
|
|
|
|
<span className={styles.postNumLink}>
|
|
|
|
|
{' '}
|
|
|
|
|
<Link to={`/p/${subplebbitAddress}`}>p/{subplebbitAddress && Plebbit.getShortAddress(subplebbitAddress)}</Link>{' '}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
{!(isDescription || isRules) &&
|
|
|
|
|
(cid ? (
|
|
|
|
|
<span className={styles.postNumLink}>
|
|
|
|
|
<Link to={`/p/${subplebbitAddress}/c/${cid}`} className={styles.linkToPost} title={t('link_to_post')} onClick={(e) => !cid && e.preventDefault()}>
|
|
|
|
|
c/
|
|
|
|
|
</Link>
|
|
|
|
|
<span className={styles.replyToPost} title={t('reply_to_post')} onMouseDown={() => openReplyModal && openReplyModal(cid, postCid, subplebbitAddress)}>
|
|
|
|
|
{shortCid}
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<span>c/</span>
|
|
|
|
|
<span className={styles.pendingCid}>
|
|
|
|
|
{state === 'failed' || stateString === 'Failed' ? _.capitalize(t('failed')) : state === 'pending' ? _.capitalize(t('pending')) : ''}
|
|
|
|
|
</span>
|
|
|
|
|
</>
|
|
|
|
|
))}
|
|
|
|
|
{pinned && (
|
|
|
|
|
<span className={`${styles.stickyIconWrapper} ${!locked && styles.addPaddingBeforeReply}`}>
|
|
|
|
|
<img src='assets/icons/sticky.gif' alt='' className={styles.stickyIcon} title={t('sticky')} />
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
{locked && (
|
|
|
|
|
<span className={`${styles.closedIconWrapper} ${styles.addPaddingBeforeReply} ${pinned && styles.addPaddingInBetween}`}>
|
|
|
|
|
<img src='assets/icons/closed.gif' alt='' className={styles.closedIcon} title={t('closed')} />
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
{!isInPostPageView && !isReply && !isHidden && (
|
|
|
|
|
<span className={styles.replyButton}>
|
|
|
|
|
[
|
|
|
|
|
<Link
|
|
|
|
|
to={isInAllView && isDescription ? '/p/all/description' : `/p/${subplebbitAddress}/${isDescription ? 'description' : isRules ? 'rules' : `c/${postCid}`}`}
|
|
|
|
|
onClick={(e) => !cid && !isDescription && !isRules && e.preventDefault()}
|
|
|
|
|
>
|
|
|
|
|
{_.capitalize(t('reply'))}
|
|
|
|
|
</Link>
|
|
|
|
|
]
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
{!(removed || deleted) && <PostMenuDesktop post={post} />}
|
|
|
|
|
{cid &&
|
|
|
|
|
parentCid &&
|
|
|
|
|
replies &&
|
|
|
|
|
replies.map(
|
|
|
|
|
(reply: Comment, index: number) => reply?.parentCid === cid && reply?.cid && <ReplyQuotePreview key={index} isBacklinkReply={true} backlinkReply={reply} />,
|
|
|
|
|
)}
|
2024-05-16 23:05:00 +02:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-16 23:17:10 +02:00
|
|
|
const PostMedia = ({ post }: PostProps) => {
|
2024-05-16 23:05:00 +02:00
|
|
|
const { t } = useTranslation();
|
2024-06-19 18:50:24 +02:00
|
|
|
const { link, spoiler } = post || {};
|
2024-10-11 21:38:16 +02:00
|
|
|
|
|
|
|
|
// some sites have CORS access, so the thumbnail can be fetched client-side, which is helpful if subplebbit.settings.fetchThumbnailUrls is false
|
|
|
|
|
const initialCommentMediaInfo = useMemo(() => getCommentMediaInfo(post), [post]);
|
|
|
|
|
const [commentMediaInfo, setCommentMediaInfo] = useState(initialCommentMediaInfo);
|
2024-10-13 12:58:29 +02:00
|
|
|
|
|
|
|
|
const fetchThumbnail = useCallback(async () => {
|
2024-10-11 21:38:16 +02:00
|
|
|
if (initialCommentMediaInfo?.type === 'webpage' && !initialCommentMediaInfo.thumbnail) {
|
2024-10-13 12:58:29 +02:00
|
|
|
const newMediaInfo = await fetchWebpageThumbnailIfNeeded(initialCommentMediaInfo);
|
|
|
|
|
setCommentMediaInfo(newMediaInfo);
|
2024-10-11 21:38:16 +02:00
|
|
|
}
|
|
|
|
|
}, [initialCommentMediaInfo]);
|
2024-07-20 16:25:20 +02:00
|
|
|
|
2024-10-13 12:58:29 +02:00
|
|
|
useEffect(() => {
|
|
|
|
|
fetchThumbnail();
|
|
|
|
|
}, [fetchThumbnail]);
|
|
|
|
|
|
2024-07-20 16:25:20 +02:00
|
|
|
const { url } = commentMediaInfo || {};
|
|
|
|
|
let type = commentMediaInfo?.type;
|
|
|
|
|
const gifFrameUrl = useFetchGifFirstFrame(url);
|
|
|
|
|
|
|
|
|
|
if (type === 'gif' && gifFrameUrl !== null) {
|
|
|
|
|
type = 'animated gif';
|
|
|
|
|
} else if (type === 'gif' && gifFrameUrl === null) {
|
|
|
|
|
type = 'static gif';
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-16 23:05:00 +02:00
|
|
|
const embedUrl = url && new URL(url);
|
2024-06-19 18:50:24 +02:00
|
|
|
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
2024-05-16 23:05:00 +02:00
|
|
|
const [showThumbnail, setShowThumbnail] = useState(true);
|
|
|
|
|
|
2024-09-07 14:11:33 +02:00
|
|
|
const mediaDimensions = getMediaDimensions(commentMediaInfo);
|
|
|
|
|
|
2024-05-16 23:05:00 +02:00
|
|
|
return (
|
2024-05-16 23:17:10 +02:00
|
|
|
<div className={styles.file}>
|
|
|
|
|
<div className={styles.fileText}>
|
|
|
|
|
{t('link')}:{' '}
|
|
|
|
|
<a href={url} target='_blank' rel='noopener noreferrer'>
|
2024-06-19 18:50:24 +02:00
|
|
|
{spoiler ? _.capitalize(t('spoiler')) : url && url.length > 30 ? url.slice(0, 30) + '...' : url}
|
2024-05-16 23:17:10 +02:00
|
|
|
</a>{' '}
|
2024-09-07 14:11:33 +02:00
|
|
|
({type && _.lowerCase(getDisplayMediaInfoType(type, t))}
|
|
|
|
|
{mediaDimensions && `, ${mediaDimensions}`})
|
2024-05-16 23:17:10 +02:00
|
|
|
{!showThumbnail && (type === 'iframe' || type === 'video' || type === 'audio') && (
|
|
|
|
|
<span>
|
|
|
|
|
{' '}
|
|
|
|
|
[
|
|
|
|
|
<span className={styles.closeMedia} onClick={() => setShowThumbnail(true)}>
|
|
|
|
|
{t('close')}
|
2024-05-16 23:05:00 +02:00
|
|
|
</span>
|
2024-05-16 23:17:10 +02:00
|
|
|
]
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
{showThumbnail && !hasThumbnail && embedUrl && canEmbed(embedUrl) && (
|
|
|
|
|
<span>
|
|
|
|
|
{' '}
|
|
|
|
|
[
|
|
|
|
|
<span className={styles.closeMedia} onClick={() => setShowThumbnail(false)}>
|
|
|
|
|
{t('open')}
|
2024-05-16 23:05:00 +02:00
|
|
|
</span>
|
2024-05-16 23:17:10 +02:00
|
|
|
]
|
|
|
|
|
</span>
|
2024-05-16 23:05:00 +02:00
|
|
|
)}
|
|
|
|
|
</div>
|
2024-07-04 21:38:01 +02:00
|
|
|
{(hasThumbnail || (!hasThumbnail && !showThumbnail) || spoiler) && (
|
2024-05-30 14:29:02 +02:00
|
|
|
<div className={styles.fileThumbnail}>
|
2024-06-03 13:52:55 +02:00
|
|
|
<CommentMedia commentMediaInfo={commentMediaInfo} post={post} showThumbnail={showThumbnail} setShowThumbnail={setShowThumbnail} />
|
2024-05-30 14:29:02 +02:00
|
|
|
</div>
|
2024-05-16 23:17:10 +02:00
|
|
|
)}
|
|
|
|
|
</div>
|
2024-05-16 23:05:00 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-17 15:29:03 +02:00
|
|
|
const PostMessage = ({ post }: PostProps) => {
|
2024-09-15 21:27:32 +02:00
|
|
|
const { cid, content, deleted, edit, isRules, original, parentCid, postCid, reason, removed, state } = post || {};
|
2024-08-26 17:05:56 +02:00
|
|
|
// TODO: commentAuthor is not yet available outside of editedComment, wait for API to be updated
|
2024-07-04 14:15:39 +02:00
|
|
|
// const banned = !!post?.commentAuthor?.banExpiresAt;
|
2024-05-31 20:10:52 +02:00
|
|
|
const { t } = useTranslation();
|
2024-05-17 15:29:03 +02:00
|
|
|
const params = useParams();
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const isInPostView = isPostPageView(location.pathname, params);
|
2024-06-19 23:00:11 +02:00
|
|
|
const [showOriginal, setShowOriginal] = useState(false);
|
2024-05-17 15:29:03 +02:00
|
|
|
|
2024-08-12 18:11:18 +02:00
|
|
|
const [showFullComment, setShowFullComment] = useState(false);
|
|
|
|
|
const displayContent = content && !isInPostView && content.length > 1000 && !showFullComment ? content.slice(0, 1000) : content;
|
2024-05-16 23:05:00 +02:00
|
|
|
|
2024-07-14 13:11:44 +02:00
|
|
|
const quotelinkReply = useComment({ commentCid: parentCid });
|
2024-05-16 23:05:00 +02:00
|
|
|
const isReply = parentCid;
|
2024-07-14 13:11:44 +02:00
|
|
|
const isReplyingToReply = (postCid && postCid !== parentCid) || quotelinkReply?.postCid !== parentCid;
|
2024-05-16 23:05:00 +02:00
|
|
|
|
|
|
|
|
const stateString = useStateString(post);
|
|
|
|
|
|
2024-07-22 18:14:22 +02:00
|
|
|
const loadingString = (
|
|
|
|
|
<div className={`${styles.stateString} ${styles.ellipsis}`}>{stateString !== 'Failed' ? <LoadingEllipsis string={stateString || t('loading')} /> : stateString}</div>
|
2024-05-16 23:05:00 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
2024-09-15 21:27:32 +02:00
|
|
|
<blockquote className={`${styles.postMessage} ${isRules && styles.rulesMessage}`}>
|
2024-09-21 12:59:16 +02:00
|
|
|
{isReply && state !== 'failed' && isReplyingToReply && !(deleted || removed) && <ReplyQuotePreview isQuotelinkReply={true} quotelinkReply={quotelinkReply} />}
|
2024-05-31 10:14:44 +02:00
|
|
|
{removed ? (
|
2024-08-26 17:05:56 +02:00
|
|
|
reason ? (
|
|
|
|
|
<>
|
|
|
|
|
<span className={styles.redEditMessage}>({t('this_post_was_removed')})</span>
|
|
|
|
|
<br />
|
|
|
|
|
<br />
|
2024-09-01 19:57:26 +02:00
|
|
|
<span className={styles.grayEditMessage}>{`${_.capitalize(t('reason'))}: "${reason}"`}</span>
|
2024-08-26 17:05:56 +02:00
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<span className={styles.grayEditMessage}>{_.capitalize(t('this_post_was_removed'))}.</span>
|
|
|
|
|
)
|
2024-05-31 10:14:44 +02:00
|
|
|
) : deleted ? (
|
2024-08-26 17:05:56 +02:00
|
|
|
reason ? (
|
|
|
|
|
<>
|
|
|
|
|
<span className={styles.grayEditMessage}>{t('user_deleted_this_post')}</span>{' '}
|
2024-09-01 19:57:26 +02:00
|
|
|
<span className={styles.grayEditMessage}>{`${_.capitalize(t('reason'))}: "${reason}"`}</span>
|
2024-08-26 17:05:56 +02:00
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<span className={styles.grayEditMessage}>{t('user_deleted_this_post')}</span>
|
|
|
|
|
)
|
2024-05-31 10:14:44 +02:00
|
|
|
) : (
|
2024-06-19 23:00:11 +02:00
|
|
|
<>
|
2024-07-04 21:38:01 +02:00
|
|
|
{!showOriginal && <Markdown content={displayContent} />}
|
2024-06-19 23:00:11 +02:00
|
|
|
{edit && original?.content !== post?.content && (
|
|
|
|
|
<span className={styles.editedInfo}>
|
2024-06-20 13:17:38 +02:00
|
|
|
{showOriginal && <Markdown content={original?.content} />}
|
2024-06-19 23:00:11 +02:00
|
|
|
<br />
|
2024-07-07 14:49:17 +02:00
|
|
|
<Trans
|
|
|
|
|
i18nKey={'comment_edited_at_timestamp'}
|
|
|
|
|
values={{ timestamp: getFormattedDate(edit?.timestamp) }}
|
|
|
|
|
shouldUnescape={true}
|
|
|
|
|
components={{ 1: <Tooltip content={getFormattedTimeAgo(edit?.timestamp)} children={<></>} /> }}
|
|
|
|
|
/>{' '}
|
2024-06-26 21:27:28 +02:00
|
|
|
{reason && <>{t('reason_reason', { reason: reason, interpolation: { escapeValue: false } })} </>}
|
2024-06-25 22:02:23 +02:00
|
|
|
{showOriginal ? (
|
|
|
|
|
<Trans
|
|
|
|
|
i18nKey={'click_here_to_hide_original'}
|
|
|
|
|
shouldUnescape={true}
|
|
|
|
|
components={{ 1: <span className={styles.showOriginal} onClick={() => setShowOriginal(!showOriginal)} /> }}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<Trans
|
|
|
|
|
i18nKey={'click_here_to_show_original'}
|
|
|
|
|
shouldUnescape={true}
|
|
|
|
|
components={{ 1: <span className={styles.showOriginal} onClick={() => setShowOriginal(!showOriginal)} /> }}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2024-06-19 23:00:11 +02:00
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
2024-05-31 10:14:44 +02:00
|
|
|
)}
|
2024-08-26 17:05:56 +02:00
|
|
|
{/* TODO: commentAuthor is not yet available outside of editedComment, wait for API to be updated */}
|
2024-07-04 14:15:39 +02:00
|
|
|
{/* {banned && (
|
2024-07-03 15:36:20 +02:00
|
|
|
<span className={styles.removedContent}>
|
2024-05-31 10:14:44 +02:00
|
|
|
<br />
|
|
|
|
|
<br />
|
2024-07-03 15:36:20 +02:00
|
|
|
<Tooltip
|
|
|
|
|
children={`(${t('user_banned')})`}
|
|
|
|
|
content={`${t('ban_expires_at', {
|
|
|
|
|
address: subplebbitAddress && Plebbit.getShortAddress(subplebbitAddress),
|
|
|
|
|
timestamp: getFormattedDate(commentAuthor?.banExpiresAt),
|
|
|
|
|
interpolation: { escapeValue: false },
|
|
|
|
|
})}${reason ? `. ${_.capitalize(t('reason'))}: "${reason}"` : ''}`}
|
|
|
|
|
/>
|
2024-05-31 10:14:44 +02:00
|
|
|
</span>
|
2024-07-04 14:15:39 +02:00
|
|
|
)} */}
|
2024-08-12 18:11:18 +02:00
|
|
|
{content?.length > 1000 && !isInPostView && !showFullComment && (
|
2024-05-16 23:17:10 +02:00
|
|
|
<span className={styles.abbr}>
|
|
|
|
|
<br />
|
2024-08-12 18:11:18 +02:00
|
|
|
<Trans i18nKey={'comment_too_long'} shouldUnescape={true} components={{ 1: <span onClick={() => setShowFullComment(true)} /> }} />
|
2024-05-16 23:17:10 +02:00
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
{!cid && state === 'pending' && stateString !== 'Failed' && (
|
|
|
|
|
<>
|
|
|
|
|
<br />
|
|
|
|
|
{loadingString}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</blockquote>
|
2024-05-16 23:05:00 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-01 10:26:38 +02:00
|
|
|
const Reply = ({ openReplyModal, 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, link, postCid, reason, removed, subplebbitAddress } = post || {};
|
2024-06-14 14:33:22 +02:00
|
|
|
const isRouteLinkToReply = useLocation().pathname.startsWith(`/p/${subplebbitAddress}/c/${cid}`);
|
|
|
|
|
const { hidden } = useHide({ cid });
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={styles.replyDesktop}>
|
|
|
|
|
<div className={styles.sideArrows}>{'>>'}</div>
|
2024-09-18 17:08:42 +02:00
|
|
|
<div className={`${styles.reply} ${isRouteLinkToReply && styles.highlight}`} data-cid={cid} data-author-address={author?.shortAddress} data-post-cid={postCid}>
|
2024-07-01 10:26:38 +02:00
|
|
|
<PostInfo openReplyModal={openReplyModal} post={post} postReplyCount={postReplyCount} roles={roles} />
|
2024-08-29 12:47:22 +02:00
|
|
|
{link && !hidden && !(deleted || removed) && isValidURL(link) && <PostMedia post={post} />}
|
2024-09-21 12:59:16 +02:00
|
|
|
{!hidden && (!(removed || deleted) || ((removed || deleted) && reason)) && <PostMessage post={post} />}
|
2024-06-14 14:33:22 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-05 22:18:45 +02:00
|
|
|
const PostDesktop = ({ openReplyModal, post, roles, showAllReplies, showReplies = true }: PostProps) => {
|
2024-07-01 10:26:38 +02:00
|
|
|
const { t } = useTranslation();
|
2024-09-21 12:50:24 +02:00
|
|
|
const { author, cid, content, deleted, link, parentCid, pinned, postCid, removed, 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();
|
|
|
|
|
const isInPendingPostView = isPendingPostView(location.pathname, params);
|
2024-05-30 14:29:02 +02:00
|
|
|
const isInPostPageView = isPostPageView(location.pathname, params);
|
2024-05-17 15:29:03 +02:00
|
|
|
|
2024-06-13 17:50:05 +02:00
|
|
|
const { hidden, unhide, hide } = useHide({ cid });
|
|
|
|
|
const isHidden = hidden && !isInPostPageView;
|
2024-05-30 18:01:37 +02:00
|
|
|
|
2024-05-16 23:05:00 +02:00
|
|
|
const replies = useReplies(post);
|
|
|
|
|
const visiblelinksCount = useCountLinksInReplies(post, 5);
|
2024-07-05 10:53:23 +02:00
|
|
|
const totalLinksCount = useCountLinksInReplies(post);
|
2024-07-16 13:13:04 +02:00
|
|
|
const replyCount = replies?.length;
|
2024-08-03 13:21:09 +02:00
|
|
|
|
2024-05-16 23:05:00 +02:00
|
|
|
const repliesCount = pinned ? replyCount : replyCount - 5;
|
2024-07-05 10:53:23 +02:00
|
|
|
const linksCount = pinned ? totalLinksCount : totalLinksCount - visiblelinksCount;
|
2024-07-01 10:26:38 +02:00
|
|
|
const { showOmittedReplies, setShowOmittedReplies } = useShowOmittedReplies();
|
2024-05-16 23:05:00 +02:00
|
|
|
|
2024-07-21 12:17:40 +02:00
|
|
|
const stateString = useStateString(post);
|
|
|
|
|
|
2024-09-15 21:27:32 +02:00
|
|
|
const subplebbit = useSubplebbit({ subplebbitAddress });
|
|
|
|
|
|
|
|
|
|
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 (
|
|
|
|
|
<div className={styles.postDesktop}>
|
2024-06-07 16:55:23 +02:00
|
|
|
{showReplies ? (
|
2024-06-05 22:18:45 +02:00
|
|
|
<div className={styles.hrWrapper}>
|
|
|
|
|
<hr />
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className={styles.replyQuotePreviewSpacer} />
|
|
|
|
|
)}
|
2024-06-14 14:33:22 +02:00
|
|
|
<div className={isHidden ? styles.postDesktopHidden : ''}>
|
2024-06-08 11:27:29 +02:00
|
|
|
{!isInPostPageView && !isDescription && !isRules && showReplies && (
|
2024-05-30 14:29:02 +02:00
|
|
|
<span className={styles.hideButtonWrapper}>
|
2024-06-13 17:50:05 +02:00
|
|
|
<span className={`${styles.hideButton} ${hidden ? styles.unhideThread : styles.hideThread}`} onClick={hidden ? unhide : hide} />
|
2024-05-16 23:05:00 +02:00
|
|
|
</span>
|
2024-05-30 14:29:02 +02:00
|
|
|
)}
|
2024-07-01 10:26:38 +02:00
|
|
|
<div data-cid={cid} data-author-address={author?.shortAddress} data-post-cid={postCid}>
|
2024-08-29 12:47:22 +02:00
|
|
|
{link && !isHidden && !(deleted || removed) && isValidURL(link) && <PostMedia post={post} />}
|
2024-09-18 17:08:42 +02:00
|
|
|
<PostInfo isHidden={hidden} openReplyModal={openReplyModal} post={post} postReplyCount={replyCount} roles={roles} />
|
2024-10-14 17:11:55 +02:00
|
|
|
{!isHidden && !content && !(deleted || removed) && <div className={styles.spacer} />}
|
2024-11-04 18:42:42 +01:00
|
|
|
{!isHidden && <PostMessage post={post} />}
|
2024-06-29 11:55:36 +02:00
|
|
|
</div>
|
2024-07-16 13:13:04 +02:00
|
|
|
{!isHidden && !isDescription && !isRules && !isInPendingPostView && (replyCount > 5 || (pinned && repliesCount > 0)) && !isInPostPageView && (
|
2024-05-30 14:29:02 +02:00
|
|
|
<span className={styles.summary}>
|
2024-07-01 10:26:38 +02:00
|
|
|
<span
|
2024-07-02 08:55:55 +02:00
|
|
|
className={`${showOmittedReplies[cid] ? styles.hideOmittedReplies : styles.showOmittedReplies} ${styles.omittedRepliesButtonWrapper}`}
|
|
|
|
|
onClick={() => setShowOmittedReplies(cid, !showOmittedReplies[cid])}
|
2024-07-01 10:26:38 +02:00
|
|
|
/>
|
2024-07-02 08:55:55 +02:00
|
|
|
{showOmittedReplies[cid] ? (
|
2024-07-01 10:26:38 +02:00
|
|
|
t('showing_all_replies')
|
|
|
|
|
) : linksCount > 0 ? (
|
2024-05-30 14:29:02 +02:00
|
|
|
<Trans
|
|
|
|
|
i18nKey={'replies_and_links_omitted'}
|
|
|
|
|
shouldUnescape={true}
|
|
|
|
|
components={{ 1: <Link to={`/p/${subplebbitAddress}/c/${cid}`} /> }}
|
|
|
|
|
values={{ repliesCount, linksCount }}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<Trans i18nKey={'replies_omitted'} shouldUnescape={true} components={{ 1: <Link to={`/p/${subplebbitAddress}/c/${cid}`} /> }} values={{ repliesCount }} />
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-05-30 18:01:37 +02:00
|
|
|
{!isHidden &&
|
2024-07-02 09:08:24 +02:00
|
|
|
!(pinned && !isInPostPageView && !showOmittedReplies[cid]) &&
|
2024-05-30 14:29:02 +02:00
|
|
|
!isInPendingPostView &&
|
|
|
|
|
replies &&
|
2024-06-05 22:18:45 +02:00
|
|
|
showReplies &&
|
2024-07-02 08:55:55 +02:00
|
|
|
(showAllReplies || showOmittedReplies[cid] ? replies : replies.slice(-5)).map((reply, index) => (
|
2024-08-31 15:19:43 +02:00
|
|
|
<div key={index} className={styles.replyContainer}>
|
2024-07-01 10:26:38 +02:00
|
|
|
<Reply openReplyModal={openReplyModal} reply={reply} roles={roles} postReplyCount={replyCount} />
|
2024-06-14 14:33:22 +02:00
|
|
|
</div>
|
|
|
|
|
))}
|
2024-09-15 21:27:32 +02:00
|
|
|
{isDescription && subplebbit?.rules && subplebbit?.rules.length > 0 && (
|
|
|
|
|
<div className={styles.replyContainer}>
|
|
|
|
|
<Reply reply={subplebbitRulesReply} />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-05-30 14:29:02 +02:00
|
|
|
</div>
|
2024-07-22 12:29:32 +02:00
|
|
|
{!isInPendingPostView &&
|
2024-08-20 16:05:19 +02:00
|
|
|
(stateString && stateString !== 'Failed' && state !== 'succeeded' ? (
|
2024-07-22 12:29:32 +02:00
|
|
|
<div className={styles.stateString}>
|
|
|
|
|
<br />
|
|
|
|
|
<LoadingEllipsis string={stateString} />
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
state === 'failed' && <span className={styles.error}>{t('failed')}</span>
|
|
|
|
|
))}
|
2024-05-16 23:05:00 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default PostDesktop;
|