| 30 | }); |
| 31 | |
| 32 | const handleVote = (newVoteType: VoteType) => { |
| 33 | let toastMessage = { |
| 34 | loading: 'Processing vote...', |
| 35 | success: 'Vote updated successfully.', |
| 36 | error: 'Error updating vote.', |
| 37 | }; |
| 38 | |
| 39 | if (voteType === newVoteType) { |
| 40 | toastMessage = { |
| 41 | loading: 'Removing vote...', |
| 42 | success: `Vote removed successfully.`, |
| 43 | error: 'Error removing vote.', |
| 44 | }; |
| 45 | } else if (voteType === null) { |
| 46 | toastMessage = { |
| 47 | loading: |
| 48 | newVoteType === VoteType.UPVOTE ? 'Upvoting...' : 'Downvoting...', |
| 49 | success: |
| 50 | newVoteType === VoteType.UPVOTE |
| 51 | ? 'Comment upvoted.' |
| 52 | : 'Comment downvoted.', |
| 53 | error: 'Error casting vote.', |
| 54 | }; |
| 55 | } else { |
| 56 | toastMessage = { |
| 57 | loading: 'Changing vote...', |
| 58 | success: |
| 59 | newVoteType === VoteType.UPVOTE |
| 60 | ? 'Changed to upvote.' |
| 61 | : 'Changed to downvote.', |
| 62 | error: 'Error changing vote.', |
| 63 | }; |
| 64 | } |
| 65 | |
| 66 | toast.promise( |
| 67 | execute({ voteType: newVoteType, commentId, currentPath, slug: '' }), |
| 68 | toastMessage, |
| 69 | ); |
| 70 | }; |
| 71 | |
| 72 | const isUpvoted = voteType === VoteType.UPVOTE; |
| 73 | const isDownvoted = voteType === VoteType.DOWNVOTE; |