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

Function useShareComment

packages/shared/src/hooks/useShareComment.ts:19–56  ·  view source on GitHub ↗
(origin: Origin)

Source from the content-addressed store, hash-verified

17}
18
19export function useShareComment(origin: Origin): UseShareComment {
20 const { logEvent } = useLogContext();
21 const { openSharePost } = useSharePost(origin);
22 const { getShortUrl } = useGetShortUrl();
23
24 const openShareComment = useCallback(
25 async (comment: Comment, post: Post) => {
26 if (shouldUseNativeShare()) {
27 try {
28 const shortUrl = await getShortUrl(
29 `${post.commentsPermalink}${getCommentHash(comment.id)}`,
30 ReferralCampaignKey.ShareComment,
31 );
32 await navigator.share({
33 text: `${post.title}\n${shortUrl}`,
34 });
35 logEvent(
36 postLogEvent(LogEvent.ShareComment, post, {
37 extra: {
38 origin,
39 provider: ShareProvider.Native,
40 commentId: comment.id,
41 },
42 }),
43 );
44 } catch (err) {
45 // Do nothing
46 }
47 } else {
48 openSharePost({ post, comment });
49 }
50 },
51 // eslint-disable-next-line react-hooks/exhaustive-deps
52 [getShortUrl, openSharePost, origin],
53 );
54
55 return { openShareComment };
56}

Callers 6

CommentFeedFunction · 0.90
PostEngagementsFunction · 0.90
EngagementRailFunction · 0.90
PostDiscussionPanelFunction · 0.90
ActivityRepliesTabFunction · 0.90
CompanionDiscussionFunction · 0.90

Calls 7

useLogContextFunction · 0.90
useSharePostFunction · 0.90
useGetShortUrlFunction · 0.90
shouldUseNativeShareFunction · 0.90
getCommentHashFunction · 0.90
postLogEventFunction · 0.90
logEventFunction · 0.85

Tested by

no test coverage detected