feat(post): when attempting to reply, alert reply or thread was deleted or removed

This commit is contained in:
Tom (plebeius.eth)
2025-03-02 12:10:16 +01:00
parent 31020bcb27
commit 0a7cda31bf
3 changed files with 29 additions and 22 deletions
+13 -5
View File
@@ -76,6 +76,18 @@ const PostInfo = ({ openReplyModal, post, postReplyCount = 0, roles, isHidden }:
const { hidden } = useHide(post);
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);
};
return (
<div className={styles.postInfo}>
{isHidden ? parentCid && <span className={styles.hiddenReplyEditMenuSpacer} /> : <EditMenu post={post} />}
@@ -160,11 +172,7 @@ const PostInfo = ({ openReplyModal, post, postReplyCount = 0, roles, isHidden }:
<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 && !(deleted || removed) && openReplyModal(cid, postCid, subplebbitAddress)}
>
<span className={styles.replyToPost} title={t('reply_to_post')} onMouseDown={onReplyModalClick}>
{shortCid}
</span>
</span>
+13 -5
View File
@@ -57,6 +57,18 @@ const PostInfoAndMedia = ({ openReplyModal, post, postReplyCount = 0, roles }: P
const { hidden } = useHide(post);
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);
};
return (
<>
<div className={styles.postInfo}>
@@ -152,11 +164,7 @@ const PostInfoAndMedia = ({ openReplyModal, post, postReplyCount = 0, roles }: P
<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 && !(deleted || removed) && openReplyModal(cid, postCid, subplebbitAddress)}
>
<span className={styles.replyToPost} title={t('reply_to_post')} onMouseDown={onReplyModalClick}>
{shortCid.slice(0, -4)}
</span>
</span>
+3 -12
View File
@@ -30,14 +30,6 @@ export const Post = ({ post, showAllReplies = false, showReplies = true, openRep
const subplebbit = useSubplebbit({ subplebbitAddress: post?.subplebbitAddress });
const isMobile = useIsMobile();
const { deleted, locked, removed } = post || {};
const isThreadClosed = deleted || locked || removed;
const { t } = useTranslation();
if (isThreadClosed) {
openReplyModal = () => alert(t('thread_closed_alert'));
}
let comment = post;
// handle pending mod or author edit
@@ -72,7 +64,7 @@ const PostPage = () => {
const subplebbit = useSubplebbit({ subplebbitAddress });
const { createdAt, description, rules, shortAddress, suggested, title } = subplebbit;
const { activeCid, threadCid, closeModal, openReplyModal, showReplyModal, scrollY, subplebbitAddress: postSubplebbitAddress } = useReplyModal();
const { activeCid, threadCid, closeModal, showReplyModal, scrollY, subplebbitAddress: postSubplebbitAddress } = useReplyModal();
const comment = useComment({ commentCid });
@@ -85,8 +77,7 @@ const PostPage = () => {
post = comment;
}
const { error, deleted, locked, removed, replyCount } = post || {};
const isThreadClosed = deleted || locked || removed;
const { error, replyCount } = post || {};
useEffect(() => {
window.scrollTo(0, 0);
@@ -128,7 +119,7 @@ const PostPage = () => {
) : isInRulesView ? (
<SubplebbitRules createdAt={createdAt} rules={rules} subplebbitAddress={subplebbitAddress} />
) : (
<Post post={post} showAllReplies={true} openReplyModal={isThreadClosed ? () => alert(t('thread_closed_alert')) : openReplyModal} />
<Post post={post} showAllReplies={true} />
)}
</div>
);