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

Function usePollVote

packages/shared/src/hooks/post/usePollVote.ts:21–47  ·  view source on GitHub ↗
({ post }: UsePollVoteProps)

Source from the content-addressed store, hash-verified

19 * Extracted from PollGrid/PollList to reduce duplication.
20 */
21export const usePollVote = ({ post }: UsePollVoteProps): UsePollVoteReturn => {
22 const { user } = useAuthContext();
23 const { onVote, isCastingVote } = usePoll({ post });
24 const [shouldAnimateResults, setShouldAnimateResults] = useState(false);
25 const onSendViewPost = useViewPost();
26
27 const handleVote = useCallback(
28 (optionId: string, text: string) => {
29 if (!isCastingVote) {
30 onVote(optionId, text);
31 setShouldAnimateResults(true);
32
33 if (!post?.id || !user?.id) {
34 return;
35 }
36 onSendViewPost(post.id);
37 }
38 },
39 [isCastingVote, onVote, post?.id, user?.id, onSendViewPost],
40 );
41
42 return {
43 handleVote,
44 shouldAnimateResults,
45 isCastingVote,
46 };
47};

Callers 2

PollList.tsxFile · 0.90
PollGrid.tsxFile · 0.90

Calls 4

useAuthContextFunction · 0.90
useViewPostFunction · 0.90
usePollFunction · 0.85
onVoteFunction · 0.85

Tested by

no test coverage detected