Skip to content

Commit 2bd7d25

Browse files
Merge pull request #274 from dreamyPatisiel/dev
2 parents fe67de4 + 22d81a0 commit 2bd7d25

3 files changed

Lines changed: 7 additions & 38 deletions

File tree

pages/pickpickpick/[id]/apiHooks/usePostVote.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
55
import { getGA } from '@utils/getCookie';
66

77
import { useToastVisibleStore } from '@stores/toastVisibleStore';
8-
import { useVotedStore } from '@stores/votedStore';
98

109
import { UNDEFINED_ERROR_MESSAGE } from '@/constants/errorMessageConstants';
1110
import { ErrorRespone } from '@/types/errorResponse';
@@ -29,7 +28,7 @@ const postVote = async (voteData: VoteDataProps) => {
2928

3029
export const usePostVote = () => {
3130
const { setToastVisible } = useToastVisibleStore();
32-
const { setUnVoted } = useVotedStore();
31+
3332
const queryClient = useQueryClient();
3433

3534
return useMutation({
@@ -39,11 +38,9 @@ export const usePostVote = () => {
3938
setToastVisible({ message: POST_VOTE_SUCCESS });
4039
await queryClient.invalidateQueries({ queryKey: ['pickData'] });
4140
queryClient.invalidateQueries({ queryKey: ['myPicksData'] });
42-
setUnVoted();
4341
},
4442

4543
onError: (error: ErrorRespone) => {
46-
setUnVoted();
4744
const errorMessage = error.response.data.message;
4845

4946
if (errorMessage == null) {

pages/pickpickpick/[id]/components/VoteButton.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { motion } from 'framer-motion';
22

3-
import { useState } from 'react';
4-
53
import { useRouter } from 'next/router';
64

75
import { cn } from '@utils/mergeStyle';
86

97
import { useToastVisibleStore } from '@stores/toastVisibleStore';
10-
import { useVotedStore } from '@stores/votedStore';
118

129
import { useMediaQueryContext } from '@/contexts/MediaQueryContext';
1310

@@ -20,21 +17,17 @@ interface VoteButtonProps {
2017
}
2118

2219
export default function VoteButton({ pickOptionData, dataIsVoted }: VoteButtonProps) {
23-
const { id: optionId, isPicked: optionIsPicked, percent, voteTotalCount } = pickOptionData ?? {};
20+
const { id: optionId, isPicked, percent, voteTotalCount } = pickOptionData ?? {};
2421

2522
const { mutate: postVoteMutate } = usePostVote();
26-
const { isVoted, setVoted } = useVotedStore();
27-
const [isPicked, setIsPicked] = useState(false);
2823

2924
const router = useRouter();
3025
const { id } = router.query;
3126
const { setToastVisible } = useToastVisibleStore();
3227
const { isMobile } = useMediaQueryContext();
3328

3429
const handleVote = () => {
35-
if (!optionIsPicked) {
36-
setIsPicked(true);
37-
setVoted();
30+
if (!isPicked) {
3831
return postVoteMutate({ pickId: id as string, pickOptionId: optionId });
3932
}
4033

@@ -45,7 +38,7 @@ export default function VoteButton({ pickOptionData, dataIsVoted }: VoteButtonPr
4538
};
4639

4740
const renderVoteResult = () => {
48-
if (!isVoted && !dataIsVoted) {
41+
if (!dataIsVoted) {
4942
return (
5043
<>
5144
<span className='h3 font-bold text-gray200'>?? %</span>
@@ -54,7 +47,7 @@ export default function VoteButton({ pickOptionData, dataIsVoted }: VoteButtonPr
5447
);
5548
}
5649

57-
const isNotVotedOrPicked = !isPicked || !optionIsPicked;
50+
const isNotVotedOrPicked = !isPicked;
5851

5952
const percentageColor = isNotVotedOrPicked ? 'text-gray100' : 'text-white';
6053
const voteCountColor = isNotVotedOrPicked ? 'text-gray200' : 'text-primary200';
@@ -71,8 +64,8 @@ export default function VoteButton({ pickOptionData, dataIsVoted }: VoteButtonPr
7164
${isMobile ? 'py-[1.6rem]' : 'py-[3.75rem] min-w-[16rem] max-h-[28.7rem]'}`;
7265

7366
const votebuttonClass = cn(VOTE_BUTTON_STYLE, {
74-
'bg-primary500 border-primary200': (isPicked && isVoted) || (optionIsPicked && dataIsVoted),
75-
'bg-gray400': (!isPicked && isVoted) || (!optionIsPicked && dataIsVoted),
67+
'bg-primary500 border-primary200': isPicked && dataIsVoted,
68+
'bg-gray400': !isPicked && dataIsVoted,
7669
});
7770

7871
return (

stores/votedStore.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)