Skip to content

Commit

Permalink
feat: 좋아요 기능 구현 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
NohWookJin committed Jan 6, 2024
1 parent 79848cf commit 8b8d986
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/components/DetailSectionTop/DetailToursInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { HeartIcon } from '@components/common/icons/Icons';
import { postLikedTours, deleteLikedTours } from '@api/tours';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useNavigate } from 'react-router-dom';
import { useState } from 'react';

interface DetailToursInfoProps {
infoData: tourDetail;
Expand All @@ -11,16 +10,13 @@ interface DetailToursInfoProps {
export default function DetailToursInfo({ infoData }: DetailToursInfoProps) {
const { title, liked, originalThumbnailUrl, id } = infoData;

const [isLiked, setIsLiked] = useState<boolean>(liked);

const navigate = useNavigate();
const queryClient = useQueryClient();

const { mutate: likeMutate } = useMutation({
mutationFn: (id: number) => postLikedTours({ id }),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['details'] });
setIsLiked(true);
},
onError: () => console.log('error'),
});
Expand All @@ -29,7 +25,6 @@ export default function DetailToursInfo({ infoData }: DetailToursInfoProps) {
mutationFn: (id: number) => deleteLikedTours({ id }),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['details'] });
setIsLiked(false);
},
onError: () => console.log('error'),
});
Expand Down Expand Up @@ -63,8 +58,7 @@ export default function DetailToursInfo({ infoData }: DetailToursInfoProps) {
</h1>
<div className="top-75 h-[24px] w-[24px] cursor-pointer">
<HeartIcon
// 최종 = props liked 기반, 현재 임시 처리(isLiked)
fill={isLiked ? '#FF2167' : '#D7D7D7'}
fill={liked ? '#FF2167' : '#D7D7D7'}
color="none"
onClick={onClickLikeButton}
/>
Expand Down

0 comments on commit 8b8d986

Please sign in to comment.