MCPcopy Create free account
hub / github.com/code100x/cms / handleVote

Function handleVote

src/components/posts/form/form-vote.tsx:37–54  ·  view source on GitHub ↗
(voteType: VoteType)

Source from the content-addressed store, hash-verified

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];

Callers 1

VoteFormFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected