From 549fc0485597473a2f60542974017d0390760a26 Mon Sep 17 00:00:00 2001 From: wnhlee <2wheeh@gmail.com> Date: Thu, 9 May 2024 22:11:04 +0900 Subject: [PATCH 1/2] feat: implement CommentCardBody --- .../comment/client/comment-card-body.tsx | 39 +++++++++++ .../hooks/comment/use-comment-card-actions.ts | 66 +++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 ui/src/components/comment/client/comment-card-body.tsx create mode 100644 ui/src/hooks/comment/use-comment-card-actions.ts diff --git a/ui/src/components/comment/client/comment-card-body.tsx b/ui/src/components/comment/client/comment-card-body.tsx new file mode 100644 index 00000000..765e7e92 --- /dev/null +++ b/ui/src/components/comment/client/comment-card-body.tsx @@ -0,0 +1,39 @@ +'use client'; + +import clsx from 'clsx'; + +import { CommentEditable } from '@/components/comment/client/comment-editable'; + +import { useCommentCardActions } from '@/hooks/comment/use-comment-card-actions'; + +export function CommentCardBody() { + return } />; +} + +function Actions() { + const { handleClickCancel, handleClickUpdate, disabled } = useCommentCardActions(); + + return ( + <> + + + + + ); +} diff --git a/ui/src/hooks/comment/use-comment-card-actions.ts b/ui/src/hooks/comment/use-comment-card-actions.ts new file mode 100644 index 00000000..9f06eb30 --- /dev/null +++ b/ui/src/hooks/comment/use-comment-card-actions.ts @@ -0,0 +1,66 @@ +'use client'; + +import { useRouter } from 'next/navigation'; + +import { useComment } from '@/context/comment/comment-context'; +import { useToast } from '@/context/common/toast-context'; + +import { useApiError } from '@/hooks/common/use-api-error'; + +import { updateComment } from '@/lib/apis/comment/client'; + +export const useCommentCardActions = () => { + const { + disabled, + setDisabled, + setContent, + setMovieName, + prepopulated, + setIsEditing, + validateAndGetData, + } = useComment(); + + if (prepopulated === undefined) { + throw new Error('content should be prepopulated'); + } + + const handleClickCancel = () => { + setDisabled(true); + + setContent(prepopulated.content); + setMovieName(prepopulated.movieName); + + setIsEditing(false); + setDisabled(false); + }; + + const router = useRouter(); + const { emitToast } = useToast(); + const { handleApiError } = useApiError(); + + const handleUpdateComment = async () => { + const data = validateAndGetData(); + + if (data === undefined) { + return; + } + + try { + await updateComment(prepopulated.id, data); + + setIsEditing(false); + emitToast('코멘트가 수정되었습니다.', 'success'); + router.refresh(); + } catch (error) { + handleApiError(error); + } + }; + + const handleClickUpdate = async () => { + setDisabled(true); + await handleUpdateComment(); + setDisabled(false); + }; + + return { disabled, handleClickCancel, handleClickUpdate: () => void handleClickUpdate() }; +}; From b4bc8ec739ed7945031d2d6aea90a056d538cf35 Mon Sep 17 00:00:00 2001 From: wnhlee <2wheeh@gmail.com> Date: Thu, 9 May 2024 22:12:39 +0900 Subject: [PATCH 2/2] feat: implement CommentCard --- .../comment/client/comment-card.tsx | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 ui/src/components/comment/client/comment-card.tsx diff --git a/ui/src/components/comment/client/comment-card.tsx b/ui/src/components/comment/client/comment-card.tsx new file mode 100644 index 00000000..d704f8a3 --- /dev/null +++ b/ui/src/components/comment/client/comment-card.tsx @@ -0,0 +1,36 @@ +'use client'; + +import { CommentCardBody } from '@/components/comment/client/comment-card-body'; +import { CommentCardFooter } from '@/components/comment/client/comment-card-footer'; +import { CommentCardHeader } from '@/components/comment/client/comment-card-header'; +import Card from '@/components/common/server/card'; + +import { CommentProvider } from '@/context/comment/comment-context'; + +import type { Comment } from '@/lib/definitions/comment'; + +export function CommentCard({ comment }: { comment: Comment }) { + return ( + + + + + + + + + + + + + + + + ); +}