@@ -2,93 +2,28 @@ import ReviewContent from "@/pages/map/components/review/ReviewContent";
22import { useNavigate } from "react-router-dom" ;
33import { useGetCompanyPreview } from "@/apis/company/queries" ;
44import { businessTypeNameMap } from "@/constants/categoryMap" ;
5- import { useState , useEffect } from "react" ;
6- import {
7- getLikedCompanies ,
8- likeCompany ,
9- unlikeCompany ,
10- } from "@/apis/company/getLikedCompanies" ;
11- import useAuthStore from "@/store/authStore" ;
5+
126import useLikeStore from "@/store/useLikeStore" ;
13- import HaveToLoginModal from "@/components/common/HaveToLoginModal" ;
147import useUserInfoStore from "@/store/userInfoStore" ;
15-
16- const dummyReviewItem = {
17- name : "김소영" ,
18- profileColor : "pink" ,
19- temperature : 74.6 ,
20- reviewContent :
21- "제품 품질도 후드러고 청건하게 잘 관리되어 있어요. 다시 방문하고 싶어요!" ,
22- reviewCategories : [ "GOOD_QUALITY" , "CLEAN" , "REVISIT" ] ,
23- } ;
8+ import { useLikeToggle } from "@/hooks/useLikeToggle" ;
249
2510const ReviewItem = ( { data } ) => {
2611 const navigate = useNavigate ( ) ;
2712 const { data : companyData } = useGetCompanyPreview ( data . companyId ) ;
28- const [ showLoginModal , setShowLoginModal ] = useState ( false ) ;
29- const [ isLiked , setIsLiked ] = useState ( false ) ;
30- const [ isLoggedIn , setIsLoggedIn ] = useState ( false ) ;
31- const [ loading , setLoading ] = useState ( true ) ;
3213
3314 const { userInfo } = useUserInfoStore ( ) ;
3415
35- const { likedMap, setLike } = useLikeStore ( ) ;
16+ const { likedMap } = useLikeStore ( ) ;
3617 const isGloballyLiked = likedMap [ data . companyId ] ?? false ;
3718
19+ const { isLoggedIn, toggleLike } = useLikeToggle ( data . companyId ) ;
20+
3821 const combinedReviews = {
3922 ...data ,
4023 name : userInfo . name ,
4124 profileColor : userInfo . profileColor ,
4225 } ;
4326
44- useEffect ( ( ) => {
45- const checkLoginAndLiked = async ( ) => {
46- const isAuthenticated = await useAuthStore . getState ( ) . checkAuth ( ) ;
47- setIsLoggedIn ( isAuthenticated ) ;
48-
49- if ( isAuthenticated && data ?. companyId ) {
50- const likedList = await getLikedCompanies ( ) ;
51- const liked = likedList . some (
52- ( c ) => String ( c . companyId ) === String ( data . companyId )
53- ) ;
54- setIsLiked ( liked ) ;
55- setLike ( data . companyId , liked ) ;
56- }
57- setLoading ( false ) ;
58- } ;
59-
60- if ( data ?. companyId ) checkLoginAndLiked ( ) ;
61- } , [ data ?. companyId ] ) ;
62-
63- const handleLikeClick = async ( ) => {
64- const isAuthenticated = await useAuthStore . getState ( ) . checkAuth ( ) ;
65- setIsLoggedIn ( isAuthenticated ) ;
66-
67- if ( ! isAuthenticated ) {
68- setShowLoginModal ( true ) ;
69- return ;
70- }
71-
72- try {
73- setLoading ( true ) ;
74- const currentLiked = likedMap [ data . companyId ] ?? false ;
75-
76- if ( currentLiked ) {
77- await unlikeCompany ( data . companyId ) ;
78- } else {
79- await likeCompany ( data . companyId ) ;
80- }
81-
82- const newLiked = ! currentLiked ;
83- setIsLiked ( newLiked ) ;
84- setLike ( data . companyId , newLiked ) ;
85- } catch ( e ) {
86- console . error ( "좋아요 토글 실패:" , e ) ;
87- } finally {
88- setLoading ( false ) ;
89- }
90- } ;
91-
9227 return (
9328 < div
9429 className = "flex flex-col rounded-md pt-6 px-5 bg-white"
@@ -107,14 +42,14 @@ const ReviewItem = ({ data }) => {
10742 < button
10843 onClick = { ( e ) => {
10944 e . stopPropagation ( ) ;
110- handleLikeClick ( ) ;
45+ toggleLike ( ) ;
11146 } }
11247 >
11348 < img
11449 src = {
11550 isLoggedIn && isGloballyLiked
11651 ? "/svgs/storeReview/fullHeartIcon.svg"
117- : "/svgs/Ic_Heart-Empty.svg"
52+ : "/svgs/common/ Ic_Heart-Empty.svg"
11853 }
11954 alt = "좋아요 버튼"
12055 className = "w-6 h-6"
0 commit comments