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

Function useSharePost

packages/shared/src/hooks/useSharePost.ts:23–86  ·  view source on GitHub ↗
(origin: Origin)

Source from the content-addressed store, hash-verified

21}
22
23export 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

Callers 12

ShareMobileFunction · 0.90
FeedFunction · 0.90
SocialShareFunction · 0.90
ReaderRailActionBarFunction · 0.90
ReaderRailActionBarV1Function · 0.90
ReaderFloatingActionBarFunction · 0.90
BriefPostHeaderActionsFunction · 0.90
PostOptionButtonContentFunction · 0.90
useShareCommentFunction · 0.90
CompanionMenuFunction · 0.90

Calls 7

useLogContextFunction · 0.90
useCopyPostLinkFunction · 0.90
useGetShortUrlFunction · 0.90
useLazyModalFunction · 0.90
usePostLogEventFunction · 0.90
logEventFunction · 0.85
postLogEventFunction · 0.85

Tested by

no test coverage detected