+
내가 응원한 이야기
@@ -59,11 +68,11 @@ const MyPageDetailPage = () => {
{kind === "리뷰" && (
<>
- {reviewsData?.length > 0 ? (
+ {!isLoadingReviews && reviewsData?.length > 0 ? (
reviewsData.map((item, idx) => (
))
- ) : (
+ ) : !isLoadingReviews && reviewsData?.length === 0 ? (
@@ -71,17 +80,17 @@ const MyPageDetailPage = () => {
없어요
- )}
+ ) : null}
>
)}
{kind === "응원" && (
<>
- {cheersData?.length > 0 ? (
+ {!isLoadingCheers && cheersData?.length > 0 ? (
cheersData.map((item) => (
))
- ) : (
+ ) : !isLoadingCheers && cheersData?.length === 0 ? (
@@ -89,7 +98,7 @@ const MyPageDetailPage = () => {
없어요
- )}
+ ) : null}
>
)}
diff --git a/src/pages/myPageDetail/components/ReviewItem.jsx b/src/pages/myPageDetail/components/ReviewItem.jsx
index 6ca3ffa..231c7e2 100644
--- a/src/pages/myPageDetail/components/ReviewItem.jsx
+++ b/src/pages/myPageDetail/components/ReviewItem.jsx
@@ -2,93 +2,28 @@ import ReviewContent from "@/pages/map/components/review/ReviewContent";
import { useNavigate } from "react-router-dom";
import { useGetCompanyPreview } from "@/apis/company/queries";
import { businessTypeNameMap } from "@/constants/categoryMap";
-import { useState, useEffect } from "react";
-import {
- getLikedCompanies,
- likeCompany,
- unlikeCompany,
-} from "@/apis/company/getLikedCompanies";
-import useAuthStore from "@/store/authStore";
+
import useLikeStore from "@/store/useLikeStore";
-import HaveToLoginModal from "@/components/common/HaveToLoginModal";
import useUserInfoStore from "@/store/userInfoStore";
-
-const dummyReviewItem = {
- name: "김소영",
- profileColor: "pink",
- temperature: 74.6,
- reviewContent:
- "제품 품질도 후드러고 청건하게 잘 관리되어 있어요. 다시 방문하고 싶어요!",
- reviewCategories: ["GOOD_QUALITY", "CLEAN", "REVISIT"],
-};
+import { useLikeToggle } from "@/hooks/useLikeToggle";
const ReviewItem = ({ data }) => {
const navigate = useNavigate();
const { data: companyData } = useGetCompanyPreview(data.companyId);
- const [showLoginModal, setShowLoginModal] = useState(false);
- const [isLiked, setIsLiked] = useState(false);
- const [isLoggedIn, setIsLoggedIn] = useState(false);
- const [loading, setLoading] = useState(true);
const { userInfo } = useUserInfoStore();
- const { likedMap, setLike } = useLikeStore();
+ const { likedMap } = useLikeStore();
const isGloballyLiked = likedMap[data.companyId] ?? false;
+ const { isLoggedIn, toggleLike } = useLikeToggle(data.companyId);
+
const combinedReviews = {
...data,
name: userInfo.name,
profileColor: userInfo.profileColor,
};
- useEffect(() => {
- const checkLoginAndLiked = async () => {
- const isAuthenticated = await useAuthStore.getState().checkAuth();
- setIsLoggedIn(isAuthenticated);
-
- if (isAuthenticated && data?.companyId) {
- const likedList = await getLikedCompanies();
- const liked = likedList.some(
- (c) => String(c.companyId) === String(data.companyId)
- );
- setIsLiked(liked);
- setLike(data.companyId, liked);
- }
- setLoading(false);
- };
-
- if (data?.companyId) checkLoginAndLiked();
- }, [data?.companyId]);
-
- const handleLikeClick = async () => {
- const isAuthenticated = await useAuthStore.getState().checkAuth();
- setIsLoggedIn(isAuthenticated);
-
- if (!isAuthenticated) {
- setShowLoginModal(true);
- return;
- }
-
- try {
- setLoading(true);
- const currentLiked = likedMap[data.companyId] ?? false;
-
- if (currentLiked) {
- await unlikeCompany(data.companyId);
- } else {
- await likeCompany(data.companyId);
- }
-
- const newLiked = !currentLiked;
- setIsLiked(newLiked);
- setLike(data.companyId, newLiked);
- } catch (e) {
- console.error("좋아요 토글 실패:", e);
- } finally {
- setLoading(false);
- }
- };
-
return (
{