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

Function useShareOrCopyLink

packages/shared/src/hooks/useShareOrCopyLink.ts:17–57  ·  view source on GitHub ↗
({
  link,
  text,
  logObject,
  cid,
}: UseShareOrCopyLinkProps)

Source from the content-addressed store, hash-verified

15 cid?: ReferralCampaignKey;
16}
17export function useShareOrCopyLink({
18 link,
19 text,
20 logObject,
21 cid,
22}: UseShareOrCopyLinkProps): ReturnType<typeof useCopyLink> {
23 const { logEvent } = useLogContext();
24 const [copying, copyLink] = useCopyLink();
25 const { getShortUrl, getTrackedUrl } = useGetShortUrl();
26
27 const onShareOrCopy: CopyNotifyFunction = async () => {
28 const logShareEvent = (provider: ShareProvider): void => {
29 if (!logObject) {
30 return;
31 }
32
33 logEvent(logObject(provider));
34 };
35
36 if (shouldUseNativeShare()) {
37 const shortLink = cid ? await getShortUrl(link, cid) : link;
38
39 try {
40 await navigator.share({
41 text: `${text}\n${shortLink}`,
42 });
43 logShareEvent(ShareProvider.Native);
44 } catch (err) {
45 // Do nothing
46 }
47 } else {
48 logShareEvent(ShareProvider.CopyLink);
49 copyLink({
50 link: cid ? getTrackedUrl(link, cid) : link,
51 shorten: !!cid,
52 });
53 }
54 };
55
56 return [copying, onShareOrCopy];
57}

Callers 10

CustomFeedOptionsMenuFunction · 0.90
ShareActionsFunction · 0.90
CopyLinkButtonFunction · 0.90
SquadOptionsButtonFunction · 0.90
ShareFunction · 0.90
ProfileUserStackFunction · 0.90
useShareAgentFunction · 0.90
WorldShareFunction · 0.90
ToolPageFunction · 0.90
AccountInvitePageFunction · 0.90

Calls 3

useLogContextFunction · 0.90
useCopyLinkFunction · 0.90
useGetShortUrlFunction · 0.90

Tested by

no test coverage detected