Skip to content

Commit

Permalink
chore: update the toast message while up or down vote of comment
Browse files Browse the repository at this point in the history
  • Loading branch information
NawinKumarSharma committed Sep 26, 2024
1 parent a1aee59 commit aaae89c
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions src/components/comment/CommentVoteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,43 @@ const CommentVoteForm: React.FC<CommentVoteFormProps> = ({
},
});

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,
);
};

Expand Down Expand Up @@ -99,4 +122,4 @@ const CommentVoteForm: React.FC<CommentVoteFormProps> = ({
);
};

export default CommentVoteForm;
export default CommentVoteForm;

0 comments on commit aaae89c

Please sign in to comment.