fix(post): mod and author edits weren't instant

This commit is contained in:
Tom (plebeius.eth)
2024-06-21 22:02:56 +02:00
parent 533fc2ffa3
commit cb745ffce6
5 changed files with 43 additions and 41 deletions
@@ -154,7 +154,7 @@ const PostMenuMobile = ({ post }: { post: Comment }) => {
document.body,
)}
{(isAccountMod || isAccountCommentAuthor) && (
<EditMenu commentCid={cid} isAccountCommentAuthor={isAccountCommentAuthor} isAccountMod={isAccountMod} isCommentAuthorMod={isCommentAuthorMod} />
<EditMenu isAccountCommentAuthor={isAccountCommentAuthor} isAccountMod={isAccountMod} isCommentAuthorMod={isCommentAuthorMod} post={post} />
)}
</>
);
+11 -5
View File
@@ -1,7 +1,7 @@
import { useEffect, useRef, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { Link, useLocation, useParams } from 'react-router-dom';
import { Comment, useAccount, useComment } from '@plebbit/plebbit-react-hooks';
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';
@@ -188,16 +188,22 @@ const PostMessageMobile = ({ post }: PostProps) => {
};
const Reply = ({ openReplyModal, reply, roles }: PostProps) => {
const { subplebbitAddress, cid } = reply || {};
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 (
<div className={styles.replyMobile}>
<div className={styles.reply}>
<div className={`${styles.replyContainer} ${isRouteLinkToReply && styles.highlight}`} id={reply?.cid}>
<PostInfoAndMedia openReplyModal={openReplyModal} post={reply} roles={roles} />
{reply.content && !hidden && <PostMessageMobile post={reply} />}
<div className={`${styles.replyContainer} ${isRouteLinkToReply && styles.highlight}`} id={cid}>
<PostInfoAndMedia openReplyModal={openReplyModal} post={post} roles={roles} />
{content && !hidden && <PostMessageMobile post={post} />}
<ReplyBacklinks post={reply} />
</div>
</div>