Skip to content

Commit c893d13

Browse files
authored
Merge pull request #1749 from gcbibek3353/fix/toastMessage
fix:taost message
2 parents ce305ff + 679a11b commit c893d13

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/components/posts/form/form-vote.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,26 @@ const VoteForm: React.FC<IVoteFormProps> = ({
3434
toast.error(error);
3535
},
3636
});
37+
3738
const handleVote = (voteType: VoteType) => {
39+
const isRemovingVote = userVoted && userVoteVal.voteType === voteType;
40+
3841
toast.promise(
3942
execute({ voteType, questionId, answerId, currentPath, slug }),
40-
voteType === VoteType.DOWNVOTE
43+
isRemovingVote
4144
? {
42-
loading: 'Downvoting...',
43-
success: 'Question has been downvoted.',
45+
loading: `Removing ${voteType.toLowerCase()}...`,
46+
success: `Your ${voteType.toLowerCase()} has been removed.`,
4447
error: 'Error',
4548
}
4649
: {
47-
loading: 'Upvoting...',
48-
success: 'Question has been upvoted.',
50+
loading: `${voteType === VoteType.UPVOTE ? 'Upvoting' : 'Downvoting'}...`,
51+
success: `Question has been ${voteType === VoteType.UPVOTE ? 'upvoted' : 'downvoted'}.`,
4952
error: 'Error',
50-
},
53+
}
5154
);
5255
};
56+
5357

5458
const userVoted = Boolean(votesArr.length);
5559
const userVoteVal = votesArr[0];

0 commit comments

Comments
 (0)