Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

댓글 리팩토링 #50

Merged
merged 1 commit into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions domain/comment/components/Comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { useState } from "react";

import { useNextRouter } from "@/hooks/useNextRouter";
import { Button, Text, Profile } from "@/components";
import { getDateDiffTextFromNow } from "@/utils/date";
import { useAuth } from "@/domain/auth/hooks/useAuth";
import { CommentForm } from "../CommentForm";
import {
useDeleteCommentMutation,
useEditCommentMutation,
} from "../../hooks/query";
import { getDateDiffTextFromNow } from "@/utils/date";

type CommentProps = {
comment: _Comment;
Expand All @@ -17,7 +18,8 @@ export function Comment({ comment }: CommentProps) {
const {
query: { reviewId },
} = useNextRouter();
const { id, nickname, content, updatedAt, likeAmount } = comment;
const { user } = useAuth();
const { id, nickname, content, updatedAt, userId } = comment;

const [isEditMode, setIsEditMode] = useState(false);

Expand All @@ -31,32 +33,28 @@ export function Comment({ comment }: CommentProps) {
};

return (
<article className="rounded-lg">
<header className="flex justify-between items-center mb-2">
<article className="rounded-lg mb-2">
<header className="flex justify-between items-center mb-2 py-2">
<Profile
nickname={nickname}
updatedAt={`${getDateDiffTextFromNow(updatedAt)} 전`}
/>
<ul className="flex">
<li>
<Button
onClick={() => setIsEditMode(true)}
className="bg-transparent dark:bg-transparent"
>
편집
</Button>
</li>
<li>
<Button
onClick={handleDeleteButtonClick}
className="bg-transparent dark:bg-transparent"
>
삭제
</Button>
</li>
</ul>
{user?.userId === String(userId) && (
<ul className="flex gap-4">
<li>
<Button as="icon" onClick={() => setIsEditMode(true)}>
편집
</Button>
</li>
<li>
<Button as="icon" onClick={handleDeleteButtonClick}>
삭제
</Button>
</li>
</ul>
)}
</header>
<Text>{content}</Text>
<Text className="py-2">{content}</Text>
{isEditMode && <CommentForm comment={comment} onSubmit={editComment} />}
</article>
);
Expand Down
1 change: 1 addition & 0 deletions types/comment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ type _Comment = {
id: number;
content: string;
updatedAt: string;
userId: number;
nickname: string;
likeAmount: number;
};