diff --git a/src/components/post/post.tsx b/src/components/post/post.tsx index adeb7f11..b81c7448 100644 --- a/src/components/post/post.tsx +++ b/src/components/post/post.tsx @@ -22,17 +22,19 @@ interface PostProps { } const Post = ({ post, index }: PostProps) => { - const { cid, content, downvoteCount, flair, link, linkHeight, linkWidth, pinned, replyCount, state, subplebbitAddress, timestamp, title, upvoteCount } = post || {}; + const { author: { displayName }, cid, content, downvoteCount, flair, link, linkHeight, linkWidth, pinned, replyCount, state, subplebbitAddress, timestamp, title, upvoteCount } = post || {}; const { shortAuthorAddress, authorAddressChanged } = useAuthorAddress({ comment: post }); const subplebbit = useSubplebbit({ subplebbitAddress }); const { t } = useTranslation(); const params = useParams(); const location = useLocation(); - const isAuthorOwner = subplebbit?.roles?.[post.author.address]?.role === 'owner'; - const isAuthorAdmin = subplebbit?.roles?.[post.author.address]?.role === 'admin'; - const isAuthorModerator = subplebbit?.roles?.[post.author.address]?.role === 'moderator'; + const authorRole = subplebbit?.roles?.[post.author.address]?.role; + const isAuthorOwner = authorRole === 'owner'; + const isAuthorAdmin = authorRole === 'admin'; + const isAuthorModerator = authorRole === 'moderator'; const moderatorClass = `${isAuthorOwner ? styles.owner : isAuthorAdmin ? styles.admin : isAuthorModerator ? styles.moderator : ''}`; + const authorRoleInitial = (isAuthorOwner && 'O') || (isAuthorAdmin && 'A') || (isAuthorModerator && 'M') || ''; const isPost = isPostView(location.pathname, params); const isPending = isPendingView(location.pathname, params); @@ -120,19 +122,17 @@ const Post = ({ post, index }: PostProps) => { )}
{t('post_submitted')} {getFormattedTimeAgo(timestamp)} {t('post_by')}{' '}
- {post?.author?.displayName && (
- {post?.author?.displayName}
- )}
+ {displayName && {displayName} }
e.preventDefault()}>
u/{post?.author?.shortAddress || shortAuthorAddress}
u/{shortAuthorAddress}
- {(isAuthorOwner || isAuthorAdmin || isAuthorModerator) && (
+ {authorRole && (
{' '}
[
-
- {(isAuthorOwner && 'O') || (isAuthorAdmin && 'A') || (isAuthorModerator && 'M')}
+
+ {authorRoleInitial}
]
diff --git a/src/components/reply-form/reply-form.tsx b/src/components/reply-form/reply-form.tsx
index 341ac0ca..6d3d259e 100644
--- a/src/components/reply-form/reply-form.tsx
+++ b/src/components/reply-form/reply-form.tsx
@@ -41,19 +41,19 @@ const ReplyForm = ({ cid, isReplyingToReply, hideReplyForm }: ReplyFormProps) =>
if (spoilerRef.current) {
spoilerRef.current.checked = false;
}
- }
+ };
const onPublish = () => {
const currentContent = textRef.current?.value || '';
const currentUrl = urlRef.current?.value || '';
-
+
if (!currentContent.trim()) {
alert(`missing content`);
return;
}
if (currentUrl && !isValidURL(currentUrl)) {
- alert("The provided link is not a valid URL.");
+ alert('The provided link is not a valid URL.');
return;
}
publishReply();
diff --git a/src/components/reply/reply.tsx b/src/components/reply/reply.tsx
index f880153f..93073bd7 100644
--- a/src/components/reply/reply.tsx
+++ b/src/components/reply/reply.tsx
@@ -69,13 +69,29 @@ const ReplyMedia = ({ commentMediaInfo, content, expanded, hasThumbnail, link, l
};
const Reply = ({ reply, depth }: ReplyProps) => {
- const { cid, content, downvoteCount, flair, link, linkHeight, linkWidth, removed, spoiler, subplebbitAddress, timestamp, upvoteCount } = reply || {};
+ const {
+ author: { displayName },
+ cid,
+ content,
+ downvoteCount,
+ flair,
+ link,
+ linkHeight,
+ linkWidth,
+ removed,
+ spoiler,
+ subplebbitAddress,
+ timestamp,
+ upvoteCount,
+ } = reply || {};
const subplebbit = useSubplebbit({ subplebbitAddress });
- const isAuthorOwner = subplebbit?.roles?.[reply.author.address]?.role === 'owner';
- const isAuthorAdmin = subplebbit?.roles?.[reply.author.address]?.role === 'admin';
- const isAuthorModerator = subplebbit?.roles?.[reply.author.address]?.role === 'moderator';
+ const authorRole = subplebbit?.roles?.[reply.author.address]?.role;
+ const isAuthorOwner = authorRole === 'owner';
+ const isAuthorAdmin = authorRole === 'admin';
+ const isAuthorModerator = authorRole === 'moderator';
const moderatorClass = `${isAuthorOwner ? styles.owner : isAuthorAdmin ? styles.admin : isAuthorModerator ? styles.moderator : ''}`;
+ const authorRoleInitial = (isAuthorOwner && 'O') || (isAuthorAdmin && 'A') || (isAuthorModerator && 'M') || '';
const { shortAuthorAddress } = useAuthorAddress({ comment: reply });
const replies = useReplies(reply);
@@ -116,9 +132,7 @@ const Reply = ({ reply, depth }: ReplyProps) => {
[–]
- {reply?.author?.displayName && (
- {reply?.author?.displayName}
- )}
+ {displayName && {displayName}}
{
@@ -126,13 +140,13 @@ const Reply = ({ reply, depth }: ReplyProps) => {
}}
className={`${styles.author} ${moderatorClass}`}
>
- {reply?.author?.displayName ? `u/${shortAuthorAddress}` : shortAuthorAddress}
+ {displayName ? `u/${shortAuthorAddress}` : shortAuthorAddress}
- {(isAuthorOwner || isAuthorAdmin || isAuthorModerator) && (
+ {authorRole && (
[
-
- {(isAuthorOwner && 'O') || (isAuthorAdmin && 'A') || (isAuthorModerator && 'M')}
+
+ {authorRoleInitial}
]{' '}
@@ -171,9 +185,7 @@ const Reply = ({ reply, depth }: ReplyProps) => {
subplebbitAddress={reply.subplebbitAddress}
showReplyForm={showReplyForm}
/>
- {isReplying && (
-