Skip to content

Commit

Permalink
Merge pull request #250 from FinalDoubleTen/FE-83--feat/myTrip
Browse files Browse the repository at this point in the history
QA: 우리의관심여행지 - 투표 취소 기능 추가
  • Loading branch information
suehub authored Jan 24, 2024
2 parents 962dfef + a278641 commit 249b95d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/components/Trip/LikedToursLists/LikedToursListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { postTripsLikeHate } from '@api/trips';
import {
ThumbsUp,
ThumbsDown,
ClickThumbsUp,
ClickThumbsDown,
StarIcon,
} from '@components/common/icons/Icons';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { postTripsLikeHate } from '@api/trips';
import { useNavigate } from 'react-router-dom';
import { useState } from 'react';

interface LikedToursListItemProps {
ourTripList: ourTripType;
Expand All @@ -34,11 +34,11 @@ const LikedToursListItem: React.FC<LikedToursListItemProps> = ({
const navigate = useNavigate();
const queryClient = useQueryClient();
const [thumbsState, setThumbsState] = useState({
prefer: false,
notPrefer: false,
prefer: prefer,
notPrefer: notPrefer,
});

const { mutate: thumbsUpMutate } = useMutation({
const { mutate: thumbsMutate } = useMutation({
mutationFn: () =>
postTripsLikeHate(
selectedTripId,
Expand All @@ -54,14 +54,20 @@ const LikedToursListItem: React.FC<LikedToursListItemProps> = ({

const onClickThumbsUpButton = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
setThumbsState({ prefer: true, notPrefer: false });
thumbsUpMutate();
setThumbsState((prev) => ({
prefer: !prev.prefer,
notPrefer: false,
}));
thumbsMutate();
};

const onClickThumbsDownButton = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
setThumbsState({ prefer: false, notPrefer: true });
thumbsUpMutate();
setThumbsState((prev) => ({
prefer: false,
notPrefer: !prev.notPrefer,
}));
thumbsMutate();
};

return (
Expand Down

0 comments on commit 249b95d

Please sign in to comment.