Skip to content

Commit

Permalink
Merge pull request #140 from FinalDoubleTen/FE-79--feat/MypageReview
Browse files Browse the repository at this point in the history
Fe 79  feat/mypage review
  • Loading branch information
seungjun222 authored Jan 11, 2024
2 parents a3939c7 + 48f3603 commit 2f455f9
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 66 deletions.
74 changes: 38 additions & 36 deletions src/components/Review/ReviewComments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,45 @@ export default function ReviewComments() {
댓글
<span className="pl-0.5 font-bold">{commentDataLength}</span>
</div>
{commentDataLength == 0 && (
<div className="mb-4 flex flex-col items-center justify-center text-sm text-gray4">
<div>댓글이 없습니다. </div>
<div>첫 댓글을 작성해보세요!</div>
</div>
)}
<InfiniteScroll
pageStart={0}
loadMore={() => fetchNextPage()}
hasMore={hasNextPage}
loader={
<div className="loader" key={0}>
Loading ...
<div className="flex flex-col">
{commentDataLength == 0 && (
<div className="mb-4 flex flex-col items-center justify-center text-sm text-gray4">
<div>댓글이 없습니다. </div>
<div>첫 댓글을 작성해보세요!</div>
</div>
}>
<div>
{reviewComments?.pages.map((group, index) => {
{
return (
<React.Fragment key={index}>
{group?.data.data.comments.content.map((item: any) => (
<CommentItem
key={item.commentId}
commentId={item.commentId}
authorNickname={item.authorNickname}
authorProfileImageUrl={item.authorProfileImageUrl}
createdTime={item.createdTime}
content={item.content}
isAuthor={item.isAuthor}
/>
))}
</React.Fragment>
);
}
})}
</div>
</InfiniteScroll>
)}
<InfiniteScroll
pageStart={0}
loadMore={() => fetchNextPage()}
hasMore={hasNextPage}
loader={
<div className="loader" key={0}>
Loading ...
</div>
}>
<div>
{reviewComments?.pages.map((group, index) => {
{
return (
<React.Fragment key={index}>
{group?.data.data.comments.content.map((item: any) => (
<CommentItem
key={item.commentId}
commentId={item.commentId}
authorNickname={item.authorNickname}
authorProfileImageUrl={item.authorProfileImageUrl}
createdTime={item.createdTime}
content={item.content}
isAuthor={item.isAuthor}
/>
))}
</React.Fragment>
);
}
})}
</div>
</InfiniteScroll>
</div>
<Modal isOpen={isModalOpen} closeModal={closeModal}>
{modalChildren === 'EditDelete' && <EditDelete />}
{modalChildren === 'MyAlert' && (
Expand Down
67 changes: 39 additions & 28 deletions src/components/common/nav/InputComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
interface InputCommentProps {
classNameName?: string;
}

interface PostCommentMutationParams {
comment: string;
reviewId: number;
}

interface EditCommentMutationParams {
comment: string;
targetCommentId: number;
}

export const InputComment: React.FC<InputCommentProps> = () => {
const [comment, setComment] = useRecoilState(commentState);
const params = useParams();
Expand All @@ -28,19 +31,29 @@ export const InputComment: React.FC<InputCommentProps> = () => {
const targetCommentId = useRecoilValue(targetCommentIdState);
const queryClient = useQueryClient();

const { mutate: postCommentMutate } = useMutation({
const { mutate: postReviewMutate } = useMutation({
mutationFn: ({ comment, reviewId }: PostCommentMutationParams) =>
postComments(comment, reviewId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['reviewComments'] });
queryClient.invalidateQueries({
queryKey: ['reviewComments'],
});
queryClient.invalidateQueries({
queryKey: ['myReviews'],
});
},
onError: () => console.log('error'),
});
const { mutate: editCommentMutate } = useMutation({
const { mutate: editReviewMutate } = useMutation({
mutationFn: ({ comment, targetCommentId }: EditCommentMutationParams) =>
putComments(comment, targetCommentId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['reviewComments'] });
queryClient.invalidateQueries({
queryKey: ['reviewComments'],
});
queryClient.invalidateQueries({
queryKey: ['myReviews'],
});
},
onError: () => console.log('error'),
});
Expand All @@ -52,10 +65,10 @@ export const InputComment: React.FC<InputCommentProps> = () => {

const handleSubmit = async () => {
if (isModifyingComment) {
await editCommentMutate({ comment, targetCommentId });
await editReviewMutate({ comment, targetCommentId });
setIsModifyingComment(false);
} else {
await postCommentMutate({ comment, reviewId });
await postReviewMutate({ comment, reviewId });
}
setComment('');
};
Expand All @@ -65,29 +78,27 @@ export const InputComment: React.FC<InputCommentProps> = () => {
}
};
return (
<>
<div className="sticky bottom-0 mt-auto flex flex h-[64px] w-full items-center justify-center border border-solid border-[#EDEDED] bg-white ">
<div className="ml-4 mr-4 flex h-[40px] w-full items-center rounded-md border border-solid border-[#EDEDED]">
<div className="pl-1 pr-0.5 text-sm font-bold text-[#29ddf6]"></div>
<div className="flex w-full ">
<input
type="text"
placeholder="댓글을 입력하세요"
className=" w-full max-w-full text-sm placeholder-[#d7d7d7] outline-none"
onChange={handleTextChange}
value={comment}
onKeyPress={handleKeyPress}
/>
</div>
<div className="ml-auto mr-1 min-w-[2rem] ">
<button
onClick={handleSubmit}
className=" text-sm font-bold text-[#29ddf6]">
등록
</button>
</div>
<div className="sticky bottom-0 mt-auto flex flex h-[64px] w-full items-center justify-center border border-solid border-[#EDEDED] bg-white ">
<div className="ml-4 mr-4 flex h-[40px] w-full items-center rounded-md border border-solid border-[#EDEDED]">
<div className="pl-1 pr-0.5 text-sm font-bold text-[#29ddf6]"></div>
<div className="flex w-full ">
<input
type="text"
placeholder="댓글을 입력하세요"
className=" w-full max-w-full text-sm placeholder-[#d7d7d7] outline-none"
onChange={handleTextChange}
value={comment}
onKeyPress={handleKeyPress}
/>
</div>
<div className="ml-auto mr-1 min-w-[2rem] ">
<button
onClick={handleSubmit}
className=" text-sm font-bold text-[#29ddf6]">
등록
</button>
</div>
</div>
</>
</div>
);
};
4 changes: 2 additions & 2 deletions src/pages/detail/detail.page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { DetailHeader } from '@components/common/header';
import DetailSectionTop from '@components/DetailSectionTop/DetailSectionTop';
import DetailSectionBottom from '@components/DetailSectionBottom/DetailSectionBottom';
import { DetailTopButton } from '@components/DetailSectionTop';
// import { DetailTopButton } from '@components/DetailSectionTop';

const DetailTours = () => {
return (
<>
<DetailHeader />
<DetailSectionTop />
<DetailSectionBottom />
<DetailTopButton />
{/* <DetailTopButton /> */}
</>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/pages/reviewComment/reviewComment.page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DetailHeader } from '@components/common/header';
import { DetailReview, ReviewComments } from '@components/Review';

const ReviewComment = () => {
return (
<>
Expand Down

0 comments on commit 2f455f9

Please sign in to comment.