Skip to content

Commit 5b029f0

Browse files
committed
feat: allows comment delete of ownPost
1 parent cc33941 commit 5b029f0

File tree

6 files changed

+28
-2
lines changed

6 files changed

+28
-2
lines changed

src/components/post/PostCommentItem.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export interface PostCommentItemProps {
129129
comment: Comment;
130130
ownComment: boolean;
131131
onRemove: (id: string) => any;
132+
ownPost: boolean;
132133
}
133134

134135
interface TogglerProps {
@@ -152,6 +153,7 @@ const PostCommentItem: React.FC<PostCommentItemProps> = ({
152153
comment,
153154
ownComment,
154155
onRemove,
156+
ownPost,
155157
}) => {
156158
const { id, user, created_at, text, replies_count, deleted, level } = comment;
157159
const [open, onToggleOpen] = useBoolean(false);
@@ -192,6 +194,11 @@ const PostCommentItem: React.FC<PostCommentItemProps> = ({
192194
<span onClick={() => onRemove(id)}>삭제</span>
193195
</div>
194196
)}
197+
{ownPost && !(ownComment && !editing) && (
198+
<div className="actions">
199+
<span onClick={() => onRemove(id)}>삭제</span>
200+
</div>
201+
)}
195202
</CommentHead>
196203
{editing ? (
197204
<PostEditComment
@@ -210,7 +217,13 @@ const PostCommentItem: React.FC<PostCommentItemProps> = ({
210217
{level < 2 && (
211218
<Toggler open={open} onToggle={onToggleOpen} count={replies_count} />
212219
)}
213-
{open && <PostRepliesContainer commentId={id} onHide={onToggleOpen} />}
220+
{open && (
221+
<PostRepliesContainer
222+
commentId={id}
223+
onHide={onToggleOpen}
224+
ownPost={ownPost}
225+
/>
226+
)}
214227
</CommentFoot>
215228
</PostCommentItemBlock>
216229
);

src/components/post/PostCommentsList.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,24 @@ export interface PostCommentsListProps {
99
comments: Comment[];
1010
currentUserId: null | string;
1111
onRemove: (id: string) => any;
12+
ownPost: boolean;
1213
}
1314

1415
const PostCommentsList: React.FC<PostCommentsListProps> = ({
1516
comments,
1617
currentUserId,
1718
onRemove,
19+
ownPost,
1820
}) => {
1921
return (
2022
<PostCommentsListBlock>
21-
{comments.map(comment => (
23+
{comments.map((comment) => (
2224
<PostCommentItem
2325
comment={comment}
2426
key={comment.id}
2527
ownComment={currentUserId === (comment.user && comment.user.id)}
2628
onRemove={onRemove}
29+
ownPost={ownPost}
2730
/>
2831
))}
2932
</PostCommentsListBlock>

src/components/post/PostReplies.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ export interface PostRepliesProps {
5757
onReply: (text: string) => any;
5858
onHide: () => void;
5959
onRemove: (id: string) => any;
60+
ownPost: boolean;
6061
}
6162

6263
const PostReplies: React.FC<PostRepliesProps> = ({
6364
comments,
6465
onReply,
6566
onHide,
6667
onRemove,
68+
ownPost,
6769
}) => {
6870
const [writing, onToggle] = useBoolean(false);
6971
const currentUserId = useUserId();
@@ -90,6 +92,7 @@ const PostReplies: React.FC<PostRepliesProps> = ({
9092
comments={comments}
9193
currentUserId={currentUserId}
9294
onRemove={onRemove}
95+
ownPost={ownPost}
9396
/>
9497
{hasComments && <Separator />}
9598
{writing || !hasComments ? (

src/containers/post/PostComments.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface PostCommentsProps {
1717
comments: Comment[];
1818
postId: string;
1919
count: number;
20+
ownPost: boolean;
2021
}
2122

2223
const MarginTop = styled.div`
@@ -27,6 +28,7 @@ const PostComments: React.FC<PostCommentsProps> = ({
2728
comments,
2829
postId,
2930
count,
31+
ownPost,
3032
}) => {
3133
const [askRemove, onToggleAskRemove] = useBoolean(false);
3234
const [removeId, setRemoveId] = useState('');
@@ -64,6 +66,7 @@ const PostComments: React.FC<PostCommentsProps> = ({
6466
comments={comments}
6567
currentUserId={currentUserId}
6668
onRemove={onRemove}
69+
ownPost={ownPost}
6770
/>
6871
</MarginTop>
6972
</PostCommentsTemplate>

src/containers/post/PostRepliesContainer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import PopupOKCancel from '../../components/common/PopupOKCancel';
1616
export interface PostRepliesProps {
1717
commentId: string;
1818
onHide: () => void;
19+
ownPost: boolean;
1920
}
2021

2122
const PostRepliesContainer: React.FC<PostRepliesProps> = ({
2223
commentId,
2324
onHide,
25+
ownPost,
2426
}) => {
2527
const [askRemove, onToggleAskRemove] = useBoolean(false);
2628
const [removeId, setRemoveId] = useState('');
@@ -76,6 +78,7 @@ const PostRepliesContainer: React.FC<PostRepliesProps> = ({
7678
<>
7779
<PostReplies
7880
comments={replies.data.comment.replies}
81+
ownPost={ownPost}
7982
onReply={onReply}
8083
onHide={onHide}
8184
onRemove={onRemove}

src/containers/post/PostViewer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ const PostViewer: React.FC<PostViewerProps> = ({
415415
count={post.comments_count}
416416
comments={post.comments}
417417
postId={post.id}
418+
ownPost={post.user.id === userId}
418419
/>
419420
{showRecommends && (userId !== null || isVeryOld) && (
420421
<RelatedPost

0 commit comments

Comments
 (0)