feat(post): add "show original" button to content edit

This commit is contained in:
Tom (plebeius.eth)
2024-06-19 23:00:11 +02:00
parent c095f1377d
commit e4febb9df0
3 changed files with 61 additions and 4 deletions
+23 -2
View File
@@ -22,6 +22,7 @@ import ReplyQuotePreview from '../reply-quote-preview';
import { PostProps } from '../../views/post/post';
import Timestamp from '../timestamp';
import _ from 'lodash';
import { getFormattedDate } from '../../lib/utils/time-utils';
const PostInfo = ({ openReplyModal, post, roles, isHidden }: PostProps) => {
const { t } = useTranslation();
@@ -162,11 +163,13 @@ const PostMedia = ({ post }: PostProps) => {
};
const PostMessage = ({ post }: PostProps) => {
const { cid, content, deleted, parentCid, postCid, reason, removed, spoiler, state, subplebbitAddress } = post || {};
const { cid, deleted, edit, original, parentCid, postCid, reason, removed, spoiler, state, subplebbitAddress } = post || {};
const { t } = useTranslation();
const params = useParams();
const location = useLocation();
const isInPostView = isPostPageView(location.pathname, params);
const [content, setContent] = useState(post?.content);
const [showOriginal, setShowOriginal] = useState(false);
const displayContent = content && !isInPostView && content.length > 1000 ? content?.slice(0, 1000) + '(...)' : content;
@@ -189,7 +192,25 @@ const PostMessage = ({ post }: PostProps) => {
) : deleted ? (
<span className={styles.deletedContent}>{t('user_deleted_this_post')}</span>
) : (
<Markdown content={displayContent} spoiler={spoiler} />
<>
<Markdown content={displayContent} spoiler={spoiler} />
{edit && original?.content !== post?.content && (
<span className={styles.editedInfo}>
<br />
(Edited at {getFormattedDate(edit?.timestamp)},{' '}
<span
className={styles.showOriginal}
onClick={() => {
setContent(showOriginal ? post?.content : original?.content);
setShowOriginal(!showOriginal);
}}
>
show {showOriginal ? 'edited' : 'original'}
</span>
)
</span>
)}
</>
)}
{(removed || deleted) && reason && (
<span>