diff --git a/src/pages/PostDetail.tsx b/src/pages/PostDetail.tsx index 6985387..0d45a4e 100644 --- a/src/pages/PostDetail.tsx +++ b/src/pages/PostDetail.tsx @@ -7,8 +7,17 @@ import { Badge } from '@/components/ui/badge'; import { Textarea } from '@/components/ui/textarea'; import { ThumbsUp, MessageCircle, ArrowLeft, MoreVertical } from 'lucide-react'; import { Separator } from '@/components/ui/separator'; -import { getPost, getPostComments, createComment } from '@/services/api'; -import { togglePostLike, togglePostDislike, togglePostScrap, getIsScraped } from '@/services/api'; +import { + getPost, + getPostComments, + createComment, + togglePostLike, + togglePostDislike, + togglePostScrap, + getIsScraped, + getCommentReactions, + getMyProfile, +} from '@/services/api'; import scrapIcon from '@/assets/scrap.svg'; import reportIcon from '@/assets/report.svg'; import writeCommentIcon from '@/assets/writecomment.svg'; @@ -108,25 +117,39 @@ export default function PostDetail() { })); }; -const handleCommentLike = async (commentId: string) => { - try { - if (!accessToken) return alert('로그인이 필요합니다.'); - await likeComment(commentId); - await refreshCommentReaction(commentId); - } catch (e) { - console.error('댓글 좋아요 실패:', e); - } -}; + // 내 프로필 정보 + const [myProfile, setMyProfile] = useState<{ + displayName: string; + initial: string; + } | null>(null); -const handleCommentDislike = async (commentId: string) => { - try { - if (!accessToken) return alert('로그인이 필요합니다.'); - await dislikeComment(commentId); - await refreshCommentReaction(commentId); - } catch (e) { - console.error('댓글 싫어요 실패:', e); - } -}; + // 프로필 팝업 상태 + const [isPostProfileOpen, setIsPostProfileOpen] = useState(false); + const [openCommentProfileId, setOpenCommentProfileId] = useState(null); + const [isMyProfileOpen, setIsMyProfileOpen] = useState(false); + + // 내 프로필 불러오기 + useEffect(() => { + const fetchMyProfile = async () => { + try { + const me = await getMyProfile(); + const name: string = + me?.displayName ?? me?.nickname ?? me?.name ?? '나'; + + setMyProfile({ + displayName: name, + initial: name.charAt(0), + }); + } catch (e) { + console.error('내 프로필 불러오기 실패:', e); + } + }; + + fetchMyProfile(); + }, []); + + useEffect(() => { + if (!comments || comments.length === 0) return; // const handleTagClick = (tag: string) => { @@ -403,42 +426,51 @@ const handleCommentDislike = async (commentId: string) => { {/* 본문 */}
- {/* 왼쪽: 프로필 + 팝업 */} -
- {/* 아바타 */} - setShowProfilePopup((v) => !v)} - className={` - w-14 h-14 rounded-full cursor-pointer - border-[5px] ${getProfileBorderClass(postData.authorNicknameColor)} - bg-white text-gray-900 font-bold - shadow-sm hover:bg-gray-50 transition - `} - > - - {postData.authorInitial} - - - - {/* 이름 + 날짜 */} -
-
-

{postData.authorName}

-
-

{postData.date}

-
- - {/* 프로필 팝업 */} - {showProfilePopup && ( - setShowProfilePopup(false)} - /> - )} -
+ {/* 왼쪽: 프로필 + 작은 팝업 */} +
+ {/* 아바타 - 클릭 시 팝업 열기 */} + setIsPostProfileOpen((prev) => !prev)} + > + + {postData.authorInitial} + + + + {/* 닉네임/날짜 */} +
+ {/* 닉네임 - 클릭 시 팝업 열기 */} + +

+ {postData.date} +

+
+ + {/* 닉네임 아래에 작게 뜨는 팝업 */} + setIsPostProfileOpen(false)} + onChatClick={() => { + setIsPostProfileOpen(false); + navigate('/chat'); + }} + /> +
+

{postData.date}

+
+
{/* 오른쪽: 스크랩/신고 메뉴 */}
@@ -529,47 +561,40 @@ const handleCommentDislike = async (commentId: string) => {
- {/* 댓글 작성 */} -
-

댓글 작성

- - {/* 아바타 + 입력 영역 한 줄 정렬 */} -
- {/* 아바타 */} - - - 나 - - - - {/* 입력창 + 버튼 */} -
-