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

[Feat] 다른 유저 프로필 보기 #160

Merged
merged 30 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
84871ea
Feat: 유저 프로필 클릭 시 정보 카드 열리도록 기능 추가
minjeong9919 Jul 9, 2024
cf172b9
Feat: 댓글 유저 프로필 클릭 시에 유저정보카드가 열리도록 구현
minjeong9919 Jul 10, 2024
a967dc8
Fix: 정렬 드롭다운 클릭 시 실시간 반영되지 않는 이슈 해결
minjeong9919 Jul 10, 2024
e45aa4f
Feat: 유저 정보 연결 및 애니메이션 추가
minjeong9919 Jul 10, 2024
73f7437
Refactor: 모든 댓글 팝오버 하나의 상태로 관리
minjeong9919 Jul 10, 2024
5c215d5
Refactor: 유저 정보 카드에 프로필 이미지 추가
minjeong9919 Jul 10, 2024
e877e19
Merge: 무한 스크롤 댓글 구현 브랜치 merge 및 충돌 해결
minjeong9919 Jul 12, 2024
baa6210
Style: css 수정
minjeong9919 Jul 12, 2024
8bfbd62
Feat: 댓글 위치에 따라 프로필 카드 위치 변경
minjeong9919 Jul 12, 2024
82cc5e7
Style: css 클래스명 수정
minjeong9919 Jul 12, 2024
9c20f3b
Refactor: 닉네임 Hover 시에도 유저 프로필 카드가 보이도록 구현
minjeong9919 Jul 13, 2024
f37dacb
Merge: 'develop'브랜치 Pull
minjeong9919 Jul 15, 2024
e08e0d9
Feat: 내 게시글 페이지 데이터 null 처리
minjeong9919 Jul 15, 2024
34c0a7f
Feat: 글 작성하기 버튼 클릭 시 로그인이 안되어있으면 모달창 열리도록 구현
minjeong9919 Jul 15, 2024
0233a81
Refactor: 커뮤니티 페이지 레이아웃 구조 변경
minjeong9919 Jul 15, 2024
2aecbd7
Refactor: 댓글 작성 비회원의 경우 처리
minjeong9919 Jul 15, 2024
64f2c7e
Refactor: 피드백 반영
minjeong9919 Jul 25, 2024
67ccc7c
Feat: 이미지 zoom 스캐너 구현
minjeong9919 Jul 25, 2024
322217e
Feat: 사진 확대 기능 구현
minjeong9919 Jul 26, 2024
82ef2ec
Refactor: 확대 비율 조절
minjeong9919 Jul 29, 2024
550190c
Refactor: image 에러 처리
minjeong9919 Jul 30, 2024
820cc94
Merge: develop 브랜치 merge
minjeong9919 Jul 30, 2024
24fa10a
Refactor: 리뷰 작성 버튼 유저 데이터 가져오도록 수정
minjeong9919 Jul 30, 2024
085632c
Refactor: hover 시에 popover 아이콘이 나오도록 수정
minjeong9919 Jul 30, 2024
99996bd
Refactor: 커뮤니티 글 작성 버튼 클릭 시에 주문 내역 가져오도록 수정
minjeong9919 Jul 30, 2024
2aba1d9
Refactor: early return 문으로 수정
minjeong9919 Jul 30, 2024
0ccde5c
Refactor: onLoadingComplete에서 onLoad로 수정
minjeong9919 Jul 30, 2024
bf83195
Fix: 경고문 해결
minjeong9919 Jul 30, 2024
106a7ed
Design: 커뮤니티 글 작성 버튼 hover color 추가
minjeong9919 Jul 30, 2024
4504451
Refactor: 피드백 반영
minjeong9919 Aug 5, 2024
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
15 changes: 15 additions & 0 deletions src/api/usersAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,18 @@ export const checkNickname = async (nickname: string) => {
throw error;
}
};

/**
* 클릭한 사용자의 정보를 반환합니다.
*/

export const getOthersInfo = async (userId: number) => {
try {
const res = await fetch(`${BASE_URL}/api/v1/users/${userId}`);
const result = await res.json();
const { data } = result;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

구조 분해로 줄일 수 있을 것 같아요

Suggested change
const result = await res.json();
const { data } = result;
const { data }= await res.json();

return data;
} catch (error) {
throw error;
}
};
6 changes: 6 additions & 0 deletions src/app/community/_components/AuthorCard.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
height: 6.4rem;
}

.user-profile {
position: relative;
}

.info-textbox {
@include flex-column(0);

Expand All @@ -16,6 +20,8 @@

& > .user-name {
@include pretendard-18-500;

cursor: pointer;
}

& > .sub-info {
Expand Down
34 changes: 29 additions & 5 deletions src/app/community/_components/AuthorCard.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import classNames from 'classnames/bind';
import { MouseEvent } from 'react';
import { useRef, useState } from 'react';

import ProfileImage from '@/components/ProfileImage/ProfileImage';
import { PopOver } from '@/components';
import UserProfileCard from './UserProfileCard';

import styles from './AuthorCard.module.scss';

Expand All @@ -12,29 +13,52 @@ interface AuthorCardProps {
nickname: string;
dateText: string;
userImage: string | null;
userId: number;
onClickPopOver: () => void;
onClosePopOver: () => void;
isOpenPopOver: boolean;
popOverOptions: {
label: string;
onClick: (e: React.MouseEvent<HTMLDivElement>) => void;
onClick: () => void;
}[];
}

export default function AuthorCard({
nickname,
dateText,
userImage,
userId,
onClickPopOver,
onClosePopOver,
isOpenPopOver,
popOverOptions,
}: AuthorCardProps) {
const userProfileCardRef = useRef<HTMLDivElement>(null);
const [isOpenUserCard, setIsOpenUserCard] = useState(false);

const handleOpenProfile = () => {
setIsOpenUserCard(true);
};

const handleCloseProfile = () => {
setIsOpenUserCard(false);
};

return (
<div className={cn('container')}>
<ProfileImage profileImage={userImage} />
<div className={cn('container')} onClick={(e) => e.stopPropagation()}>
<div
onMouseEnter={handleOpenProfile}
onMouseLeave={handleCloseProfile}
className={cn('user-profile')}
ref={userProfileCardRef}
>
<ProfileImage profileImage={userImage} />
<UserProfileCard isOpenProfileCard={isOpenUserCard} userId={userId} />
</div>
<div className={cn('info-textbox')}>
<p className={cn('user-name')}>{nickname}</p>
<p className={cn('user-name')} onMouseEnter={handleOpenProfile} onMouseLeave={handleCloseProfile}>
{nickname}
</p>
<p className={cn('sub-info')}>{dateText}</p>
</div>
<div className={cn('show-more-icon')}>
Expand Down
7 changes: 7 additions & 0 deletions src/app/community/_components/Comment.module.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
.container {
display: flex;
position: relative;
width: 100%;
gap: 1.2rem;
}

.user-profile {
position: relative;
}

.profile-image {
@include flex-center;

Expand Down Expand Up @@ -34,6 +39,8 @@

& > .nickname {
@include pretendard-16-400;

cursor: pointer;
}

& > .time-ago {
Expand Down
65 changes: 43 additions & 22 deletions src/app/community/_components/Comment.tsx
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);

Expand All @@ -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 {
Expand All @@ -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,
Expand All @@ -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]);
Copy link
Contributor

Choose a reason for hiding this comment

The 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 = () => {
Expand All @@ -84,14 +100,19 @@ export default forwardRef<HTMLDivElement, CommentProps>(function Comment({ cardI

const handleClickReport = () => {};
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
Expand All @@ -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>
Expand Down
34 changes: 18 additions & 16 deletions src/app/community/_components/PostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

호옥시 apdate 오타인가용?

Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import classNames from 'classnames/bind';
import { FallbackProps } from 'react-error-boundary';
import { Button } from '@/components';

import styles from './ErrorFallbackDetailModal.module.scss';

const cn = classNames.bind(styles);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.container {
padding: 4rem;

// animation: scale-in-center 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
border-radius: 1.6rem;
background-color: $white;
}
Expand Down Expand Up @@ -60,6 +58,7 @@
.right-wrapper {
@include flex-column(0);

position: relative;
justify-content: space-between;
}

Expand Down
Loading