(origin: Origin)
| 21 | } |
| 22 | |
| 23 | export function useSharePost(origin: Origin): UseSharePost { |
| 24 | const { logEvent } = useLogContext(); |
| 25 | const [, copyLink] = useCopyPostLink(); |
| 26 | const { getShortUrl, getTrackedUrl } = useGetShortUrl(); |
| 27 | const { openModal } = useLazyModal(); |
| 28 | const postLogEvent = usePostLogEvent(); |
| 29 | |
| 30 | const openSharePost = useCallback( |
| 31 | (props: FuncProps) => |
| 32 | openModal({ |
| 33 | type: LazyModal.Share, |
| 34 | props: { ...props, origin }, |
| 35 | }), |
| 36 | [openModal, origin], |
| 37 | ); |
| 38 | |
| 39 | const copyLinkShare: UseSharePost['copyLink'] = useCallback( |
| 40 | ({ post, columns, column, row }) => { |
| 41 | logEvent( |
| 42 | postLogEvent(LogEvent.SharePost, post, { |
| 43 | columns, |
| 44 | column, |
| 45 | row, |
| 46 | extra: { provider: ShareProvider.CopyLink, origin }, |
| 47 | }), |
| 48 | ); |
| 49 | const trackedLink = getTrackedUrl( |
| 50 | post.commentsPermalink, |
| 51 | ReferralCampaignKey.SharePost, |
| 52 | ); |
| 53 | copyLink({ link: trackedLink, shorten: true }); |
| 54 | }, |
| 55 | [logEvent, origin, getTrackedUrl, copyLink, postLogEvent], |
| 56 | ); |
| 57 | |
| 58 | const openNativeSharePost = useCallback( |
| 59 | async (post: Post) => { |
| 60 | try { |
| 61 | const shortLink = await getShortUrl( |
| 62 | post.commentsPermalink, |
| 63 | ReferralCampaignKey.SharePost, |
| 64 | ); |
| 65 | await navigator.share({ |
| 66 | title: post.title, |
| 67 | url: shortLink, |
| 68 | }); |
| 69 | logEvent( |
| 70 | postLogEvent(LogEvent.SharePost, post, { |
| 71 | extra: { origin, provider: ShareProvider.Native }, |
| 72 | }), |
| 73 | ); |
| 74 | } catch (err) { |
| 75 | // Do nothing |
| 76 | } |
| 77 | }, |
| 78 | [getShortUrl, origin, logEvent, postLogEvent], |
| 79 | ); |
| 80 |
no test coverage detected