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

Function CommentVoteForm

src/components/comment/CommentVoteForm.tsx:18–123  ·  view source on GitHub ↗
({
  upVotes,
  downVotes,
  commentId,
  voteType,
})

Source from the content-addressed store, hash-verified

16}
17
18const CommentVoteForm: React.FC<CommentVoteFormProps> = ({
19 upVotes,
20 downVotes,
21 commentId,
22 voteType,
23}) => {
24 const currentPath = usePathname();
25 const { execute, isLoading } = useAction(voteHandlerAction, {
26 onSuccess: () => {},
27 onError: (error) => {
28 toast.error(error);
29 },
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;
74
75 return (

Callers

nothing calls this directly

Calls 2

useActionFunction · 0.90
handleVoteFunction · 0.70

Tested by

no test coverage detected