Skip to content

Commit

Permalink
update comment tools
Browse files Browse the repository at this point in the history
  • Loading branch information
plebeius-eth committed Mar 6, 2024
1 parent 6516245 commit ff9d1fe
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
64 changes: 51 additions & 13 deletions src/components/post/comment-tools/comment-tools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import { Author, useAccount, useComment, useSubplebbit } from '@plebbit/plebbit-
import styles from './comment-tools.module.css';
import EditMenu from './edit-menu';
import HideMenu from './hide-menu';
import Label from '../label';
import ModMenu from './mod-menu';
import ShareMenu from './share-menu';
import { isInboxView } from '../../../lib/utils/view-utils';

interface CommentToolsProps {
author?: Author;
cid: string;
deleted?: boolean;
failed?: boolean;
editState?: string;
hasLabel?: boolean;
index?: number;
isAuthor?: boolean;
Expand All @@ -20,6 +23,7 @@ interface CommentToolsProps {
isSingleReply?: boolean;
parentCid?: string;
postCid?: string;
removed?: boolean;
replyCount?: number;
spoiler?: boolean | undefined;
subplebbitAddress: string;
Expand Down Expand Up @@ -193,16 +197,38 @@ const SingleReplyTools = ({
);
};

const CommentToolsLabel = ({ cid, deleted, failed, editState, isReply, removed, spoiler }: CommentToolsProps) => {
const { t } = useTranslation();
const pending = cid === undefined && !isReply && !failed;
const failedEdit = editState === 'failed';
const pendingEdit = editState === 'pending';

return (
<>
{spoiler && <Label color='black' text={t('spoiler')} />}
{pending && <Label color='yellow' text={t('pending')} />}
{failed && <Label color='red' text={t('failed')} />}
{deleted && <Label color='red' text={t('deleted')} />}
{removed && <Label color='red' text={t('removed')} />}
{failedEdit && <Label color='red' text={t('failed_edit')} />}
{pendingEdit && <Label color='yellow' text={t('pending_edit')} />}
</>
);
};

const CommentTools = ({
author,
cid,
deleted,
failed,
editState,
hasLabel = false,
index,
isReply,
isSingleReply,
parentCid,
postCid,
removed,
replyCount,
spoiler,
subplebbitAddress,
Expand Down Expand Up @@ -250,19 +276,31 @@ const CommentTools = ({
/>
)
) : (
<PostTools
author={author}
cid={cid}
failed={failed}
hasLabel={hasLabel}
index={index}
isAuthor={isAuthor}
isMod={isMod}
replyCount={replyCount}
showCommentEditForm={showCommentEditForm}
spoiler={spoiler}
subplebbitAddress={subplebbitAddress}
/>
<>
<CommentToolsLabel
cid={cid}
deleted={deleted}
failed={failed}
editState={editState}
isReply={isReply}
removed={removed}
spoiler={spoiler}
subplebbitAddress={subplebbitAddress}
/>
<PostTools
author={author}
cid={cid}
failed={failed}
hasLabel={hasLabel}
index={index}
isAuthor={isAuthor}
isMod={isMod}
replyCount={replyCount}
showCommentEditForm={showCommentEditForm}
spoiler={spoiler}
subplebbitAddress={subplebbitAddress}
/>
</>
)}
</ul>
);
Expand Down
5 changes: 4 additions & 1 deletion src/components/post/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const Post = ({ index, post = {} }: PostProps) => {
post = op;
}
// handle pending mod or author edit
const { editedComment } = useEditedComment({ comment: post });
const { state: editState, editedComment } = useEditedComment({ comment: post });
if (editedComment) {
post = editedComment;
}
Expand Down Expand Up @@ -286,8 +286,11 @@ const Post = ({ index, post = {} }: PostProps) => {
<CommentTools
author={author}
cid={cid}
deleted={deleted}
failed={state === 'failed'}
editState={editState}
index={post?.index}
removed={removed}
replyCount={replyCount}
showCommentEditForm={showCommentEditForm}
spoiler={spoiler}
Expand Down

0 comments on commit ff9d1fe

Please sign in to comment.