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

Function useShareOrCopyLink

packages/shared/src/hooks/useShareOrCopyLink.ts:17–53  ·  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 } = useGetShortUrl();
26
27 const onShareOrCopy: CopyNotifyFunction = async () => {
28 const shortLink = cid ? await getShortUrl(link, cid) : link;
29 const logShareEvent = (provider: ShareProvider): void => {
30 if (!logObject) {
31 return;
32 }
33
34 logEvent(logObject(provider));
35 };
36
37 if (shouldUseNativeShare()) {
38 try {
39 await navigator.share({
40 text: `${text}\n${shortLink}`,
41 });
42 logShareEvent(ShareProvider.Native);
43 } catch (err) {
44 // Do nothing
45 }
46 } else {
47 logShareEvent(ShareProvider.CopyLink);
48 copyLink({ link: shortLink });
49 }
50 };
51
52 return [copying, onShareOrCopy];
53}

Callers 5

CustomFeedOptionsMenuFunction · 0.90
LiveRoomInnerFunction · 0.90
SquadOptionsButtonFunction · 0.90
ShareFunction · 0.90
AccountInvitePageFunction · 0.90

Calls 3

useLogContextFunction · 0.90
useCopyLinkFunction · 0.90
useGetShortUrlFunction · 0.90

Tested by

no test coverage detected