| 35 | }); |
| 36 | |
| 37 | const handleVote = (voteType: VoteType) => { |
| 38 | const isRemovingVote = userVoted && userVoteVal.voteType === voteType; |
| 39 | |
| 40 | toast.promise( |
| 41 | execute({ voteType, questionId, answerId, currentPath, slug }), |
| 42 | isRemovingVote |
| 43 | ? { |
| 44 | loading: `Removing ${voteType.toLowerCase()}...`, |
| 45 | success: `Your ${voteType.toLowerCase()} has been removed.`, |
| 46 | error: 'Error', |
| 47 | } |
| 48 | : { |
| 49 | loading: `${voteType === VoteType.UPVOTE ? 'Upvoting' : 'Downvoting'}...`, |
| 50 | success: `Question has been ${voteType === VoteType.UPVOTE ? 'upvoted' : 'downvoted'}.`, |
| 51 | error: 'Error', |
| 52 | } |
| 53 | ); |
| 54 | }; |
| 55 | |
| 56 | const userVoted = Boolean(votesArr.length); |
| 57 | const userVoteVal = votesArr[0]; |