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

Function useSharePost

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

Source from the content-addressed store, hash-verified

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

Callers 14

ShareMobileFunction · 0.90
FeedFunction · 0.90
useBookmarkActionsFunction · 0.90
SocialShareFunction · 0.90
BriefListItemFunction · 0.90
ReaderRailActionBarFunction · 0.90
ReaderRailActionBarV1Function · 0.90
ReaderFloatingActionBarFunction · 0.90
BriefPostHeaderActionsFunction · 0.90
PostOptionButtonContentFunction · 0.90

Calls 9

useLogContextFunction · 0.90
useCopyPostLinkFunction · 0.90
useGetShortUrlFunction · 0.90
useLazyModalFunction · 0.90
usePostLogEventFunction · 0.90
openModalFunction · 0.85
logEventFunction · 0.85
postLogEventFunction · 0.85
copyLinkFunction · 0.50

Tested by

no test coverage detected