(origin: Origin)
| 17 | } |
| 18 | |
| 19 | export 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 | } |
no test coverage detected