-
Notifications
You must be signed in to change notification settings - Fork 3
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
[Feat] 다른 유저 프로필 보기 #160
The head ref may contain hidden characters: "150-feat-\uB2E4\uB978-\uC720\uC800-\uD504\uB85C\uD544-\uBCF4\uAE30"
[Feat] 다른 유저 프로필 보기 #160
Changes from 16 commits
84871ea
cf172b9
a967dc8
e45aa4f
73f7437
5c215d5
e877e19
baa6210
8bfbd62
82cc5e7
9c20f3b
f37dacb
e08e0d9
34c0a7f
0233a81
2aecbd7
64f2c7e
67ccc7c
322217e
82ef2ec
550190c
820cc94
24fa10a
085632c
99996bd
2aba1d9
0ccde5c
bf83195
106a7ed
4504451
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
'use client'; | ||
|
||
import classNames from 'classnames/bind'; | ||
import { useState, forwardRef } from 'react'; | ||
import { forwardRef, useState, MouseEvent, useEffect } from 'react'; | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { toast } from 'react-toastify'; | ||
|
||
import ProfileImage from '@/components/ProfileImage/ProfileImage'; | ||
import { calculateTimeDifference } from '@/libs/calculateDate'; | ||
import type { Users } from '@/types/userType'; | ||
import type { UserDataResponseType } from '@/types/userType'; | ||
import { PopOver } from '@/components'; | ||
import { deleteComment } from '@/api/communityAPI'; | ||
|
||
import { communityPopOverOption } from '@/libs/communityPopOverOption'; | ||
|
||
import styles from './Comment.module.scss'; | ||
import UserProfileCard from './UserProfileCard'; | ||
|
||
const cn = classNames.bind(styles); | ||
|
||
|
@@ -27,16 +28,17 @@ interface CommentDataType { | |
|
||
interface CommentProps { | ||
cardId: number; | ||
onOpenPopOver: (commentId: number) => void; | ||
onClosePopOver: () => void; | ||
commentData: CommentDataType; | ||
isOpenedPopOver: boolean; | ||
onOpenProfileCard: () => void; | ||
} | ||
|
||
interface UserDataType { | ||
data: Users; | ||
status: string; | ||
message: string; | ||
} | ||
|
||
export default forwardRef<HTMLDivElement, CommentProps>(function Comment({ cardId, commentData }, ref) { | ||
export default forwardRef<HTMLDivElement, CommentProps>(function Comment( | ||
{ cardId, commentData, onOpenPopOver, onClosePopOver, isOpenedPopOver, onOpenProfileCard }, | ||
ref, | ||
) { | ||
const queryClient = useQueryClient(); | ||
|
||
const { | ||
|
@@ -47,12 +49,16 @@ export default forwardRef<HTMLDivElement, CommentProps>(function Comment({ cardI | |
content: comment, | ||
createdAt: createdTime, | ||
} = commentData; | ||
const createdTimeToDate = new Date(createdTime); | ||
|
||
const createdTimeToDate = new Date(createdTime); | ||
const [isOpenPopOver, setIsOpenPopOver] = useState(false); | ||
const [isOpenProfileCard, setIsOpenProfileCard] = useState(false); | ||
const [commentPositionTop, setCommentPositionTop] = useState(0); | ||
|
||
const userData = queryClient.getQueryData<UserDataResponseType>(['userData']); | ||
|
||
const userData = queryClient.getQueryData<UserDataType>(['userData']); | ||
const userID = userData?.data?.id; | ||
const timeAgo = calculateTimeDifference(createdTimeToDate); | ||
|
||
const { mutate: deleteCommentMutation } = useMutation({ | ||
mutationFn: deleteComment, | ||
|
@@ -68,12 +74,22 @@ export default forwardRef<HTMLDivElement, CommentProps>(function Comment({ cardI | |
}, | ||
}); | ||
|
||
const handleClickPopOver = () => { | ||
setIsOpenPopOver(!isOpenPopOver); | ||
const handleOpenProfile = (e: MouseEvent<HTMLDivElement>) => { | ||
onOpenProfileCard(); | ||
const { top } = e.currentTarget.getBoundingClientRect(); | ||
setCommentPositionTop(top); | ||
setIsOpenProfileCard(true); | ||
}; | ||
|
||
useEffect(() => {}, [commentPositionTop]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이건 꼭 필요한건가요? |
||
|
||
const handleCloseProfile = () => { | ||
setIsOpenProfileCard(false); | ||
}; | ||
|
||
const handleClosePopOver = () => { | ||
setIsOpenPopOver(false); | ||
const handleClickPopOver = () => { | ||
onOpenPopOver(commentId); | ||
setIsOpenPopOver(true); | ||
}; | ||
|
||
const handleClickDelete = () => { | ||
|
@@ -84,14 +100,19 @@ export default forwardRef<HTMLDivElement, CommentProps>(function Comment({ cardI | |
|
||
const handleClickReport = () => {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아무 동작도 안하는 함수인듯 한데 필요한가요? |
||
|
||
const timeAgo = calculateTimeDifference(createdTimeToDate); | ||
|
||
return ( | ||
<div className={cn('container')} ref={ref}> | ||
<ProfileImage profileImage={profile && profile} /> | ||
<div onMouseEnter={handleOpenProfile} onMouseLeave={handleCloseProfile}> | ||
<ProfileImage profileImage={profile && profile} /> | ||
<UserProfileCard | ||
isOpenProfileCard={isOpenProfileCard} | ||
userId={commentUserId} | ||
positionTop={commentPositionTop} | ||
/> | ||
</div> | ||
<div className={cn('content-wrapper')}> | ||
<div className={cn('user-info-wrapper')}> | ||
<div className={cn('user-info')}> | ||
<div className={cn('user-info')} onMouseEnter={handleOpenProfile} onMouseLeave={handleCloseProfile}> | ||
<p className={cn('nickname')}>{nickname}</p> | ||
<p className={cn('time-ago')}>{timeAgo}</p> | ||
</div> | ||
|
@@ -102,9 +123,9 @@ export default forwardRef<HTMLDivElement, CommentProps>(function Comment({ cardI | |
onClickEdit: handleClickEdit, | ||
onClickReport: handleClickReport, | ||
})} | ||
isOpenPopOver={isOpenPopOver} | ||
isOpenPopOver={isOpenPopOver && isOpenedPopOver} | ||
onHandleOpen={handleClickPopOver} | ||
onHandleClose={handleClosePopOver} | ||
onHandleClose={onClosePopOver} | ||
/> | ||
</div> | ||
<div className={cn('content')}>{comment}</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ import { communityPopOverOption } from '@/libs/communityPopOverOption'; | |
import AuthorCard from './AuthorCard'; | ||
import PostCardDetailModal from './PostCardDetailModal/PostCardDetailModal'; | ||
import { PostInteractions } from './PostInteractions'; | ||
import DetailModalSkeleton from './PostCardDetailModal/ModalSkeleton'; | ||
import DetailModalSkeleton from '../../../components/ModalSkeleton/ModalSkeleton'; | ||
import ErrorFallbackDetailModal from './PostCardDetailModal/ErrorFallbackDetailModal'; | ||
|
||
import styles from './PostCard.module.scss'; | ||
|
@@ -36,7 +36,7 @@ export default function PostCard({ cardData, isMine }: PostCardProps) { | |
const [isPopOverOpen, setIsPopOverOpen] = useState(false); | ||
const [isEditModalOpen, setIsEditModalOpen] = useState(false); | ||
|
||
const { id, nickName, updateAt, title, thumbnail, likeCount, commentCount, userImage, isLiked } = cardData; | ||
const { userId, id, nickName, updateAt, title, thumbnail, likeCount, commentCount, userImage, isLiked } = cardData; | ||
|
||
const ApdatedDate = new Date(updateAt); | ||
const timeToString = calculateTimeDifference(ApdatedDate); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 호옥시 apdate 오타인가용? |
||
|
@@ -104,21 +104,22 @@ export default function PostCard({ cardData, isMine }: PostCardProps) { | |
|
||
return ( | ||
<div className={cn('container')}> | ||
<AuthorCard | ||
userId={userId} | ||
nickname={nickName} | ||
dateText={timeToString} | ||
userImage={userImage} | ||
onClickPopOver={handleClickPopOver} | ||
onClosePopOver={handleClosePopOver} | ||
isOpenPopOver={isPopOverOpen} | ||
popOverOptions={communityPopOverOption({ | ||
isMine, | ||
onClickDelete: handleClickDelete, | ||
onClickReport: handleClickReport, | ||
onClickEdit: handleClickEdit, | ||
})} | ||
/> | ||
<div className={cn('container')} onClick={handleClickPostModal}> | ||
<AuthorCard | ||
nickname={nickName} | ||
dateText={timeToString} | ||
userImage={userImage} | ||
onClickPopOver={handleClickPopOver} | ||
onClosePopOver={handleClosePopOver} | ||
isOpenPopOver={isPopOverOpen} | ||
popOverOptions={communityPopOverOption({ | ||
isMine, | ||
onClickDelete: handleClickDelete, | ||
onClickReport: handleClickReport, | ||
onClickEdit: handleClickEdit, | ||
})} | ||
/> | ||
<div className={cn('keyboard-image-wrapper')}> | ||
<Image | ||
fill | ||
|
@@ -140,6 +141,7 @@ export default function PostCard({ cardData, isMine }: PostCardProps) { | |
<Suspense fallback={<DetailModalSkeleton />}> | ||
<PostCardDetailModal | ||
cardId={id} | ||
userId={userId} | ||
onClose={handleClosePostModal} | ||
isMine={isMine} | ||
commentCount={commentCount} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
구조 분해로 줄일 수 있을 것 같아요