diff --git a/src/components/comment/CommentVoteForm.tsx b/src/components/comment/CommentVoteForm.tsx index 5c789a9a..3ceedfcd 100644 --- a/src/components/comment/CommentVoteForm.tsx +++ b/src/components/comment/CommentVoteForm.tsx @@ -29,20 +29,43 @@ const CommentVoteForm: React.FC = ({ }, }); - const handleVote = (voteType: VoteType) => { + const handleVote = (newVoteType: VoteType) => { + let toastMessage = { + loading: 'Processing vote...', + success: 'Vote updated successfully.', + error: 'Error updating vote.', + }; + + if (voteType === newVoteType) { + toastMessage = { + loading: 'Removing vote...', + success: `Vote removed successfully.`, + error: 'Error removing vote.', + }; + } else if (voteType === null) { + toastMessage = { + loading: + newVoteType === VoteType.UPVOTE ? 'Upvoting...' : 'Downvoting...', + success: + newVoteType === VoteType.UPVOTE + ? 'Comment upvoted.' + : 'Comment downvoted.', + error: 'Error casting vote.', + }; + } else { + toastMessage = { + loading: 'Changing vote...', + success: + newVoteType === VoteType.UPVOTE + ? 'Changed to upvote.' + : 'Changed to downvote.', + error: 'Error changing vote.', + }; + } + toast.promise( - execute({ voteType, commentId, currentPath }), - voteType === VoteType.DOWNVOTE - ? { - loading: 'Downvoting...', - success: 'Comment has been downvoted.', - error: 'Error', - } - : { - loading: 'Upvoting...', - success: 'Comment has been upvoted.', - error: 'Error', - }, + execute({ voteType: newVoteType, commentId, currentPath }), + toastMessage, ); }; @@ -99,4 +122,4 @@ const CommentVoteForm: React.FC = ({ ); }; -export default CommentVoteForm; +export default CommentVoteForm; \ No newline at end of file