MCPcopy Create free account
hub / github.com/dailydotdev/apps / useVoteComment

Function useVoteComment

packages/shared/src/hooks/vote/useVoteComment.ts:32–126  ·  view source on GitHub ↗
({
  onMutate,
  variables,
}: Omit<UseVoteProps, 'entity'> = {})

Source from the content-addressed store, hash-verified

30};
31
32export const useVoteComment = ({
33 onMutate,
34 variables,
35}: Omit<UseVoteProps, 'entity'> = {}): Pick<
36 UseVote<
37 VoteEntityPayload & {
38 post: Post;
39 }
40 >,
41 'toggleUpvote' | 'toggleDownvote'
42> => {
43 const { user, showLogin } = useContext(AuthContext);
44 const { logEvent } = useLogContext();
45
46 const { upvote, downvote, cancelVote } = useVote({
47 onMutate,
48 entity: UserVoteEntity.Comment,
49 variables,
50 });
51
52 return {
53 toggleUpvote: useCallback(
54 async ({ payload: comment, origin, opts }) => {
55 if (!user) {
56 showLogin({ trigger: AuthTriggers.CommentUpvote });
57
58 return;
59 }
60
61 const logsOptions = prepareVoteCommentLogsOptions({
62 payload: comment,
63 origin,
64 opts,
65 });
66
67 if (comment.userState?.vote === UserVote.Up) {
68 logEvent(
69 postLogEvent(
70 LogEvent.RemoveCommentUpvote,
71 comment.post,
72 logsOptions,
73 ),
74 );
75
76 await cancelVote({ id: comment.id });
77
78 return;
79 }
80
81 logEvent(
82 postLogEvent(LogEvent.UpvoteComment, comment.post, logsOptions),
83 );
84
85 await upvote({ id: comment.id });
86 },
87 [upvote, cancelVote, showLogin, logEvent, user],
88 ),
89 toggleDownvote: useCallback(

Callers 2

CommentActionButtonsFunction · 0.90
CommentActionButtonsV1Function · 0.90

Calls 6

useLogContextFunction · 0.90
useVoteFunction · 0.90
postLogEventFunction · 0.90
logEventFunction · 0.85
upvoteFunction · 0.85

Tested by

no test coverage detected