11import { motion } from 'framer-motion' ;
22
3- import { useState } from 'react' ;
4-
53import { useRouter } from 'next/router' ;
64
75import { cn } from '@utils/mergeStyle' ;
86
97import { useToastVisibleStore } from '@stores/toastVisibleStore' ;
10- import { useVotedStore } from '@stores/votedStore' ;
118
129import { useMediaQueryContext } from '@/contexts/MediaQueryContext' ;
1310
@@ -20,21 +17,17 @@ interface VoteButtonProps {
2017}
2118
2219export 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 (
0 commit comments