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

Function copy

packages/shared/src/hooks/useCopy.ts:30–64  ·  view source on GitHub ↗
(props = {})

Source from the content-addressed store, hash-verified

28 const { getShortUrl } = useGetShortUrl();
29
30 const copy: CopyNotifyFunction = async (props = {}) => {
31 const link = props.link || getLink();
32 const shortenLink = props.shorten || shorten;
33
34 if (link) {
35 // write the link to clipboard
36 await navigator.clipboard.writeText(link);
37
38 // try with a shortened link as well, if requested
39 if (shortenLink) {
40 try {
41 const clipBoardItem = new ClipboardItem({
42 'text/plain': getShortUrl(link).then((shortenedLink) => {
43 return new Blob([shortenedLink], { type: 'text/plain' });
44 }),
45 });
46 await navigator.clipboard.write([clipBoardItem]);
47 } catch (e) {
48 // eslint-disable-next-line no-console
49 console.warn('Error copying to clipboard', e);
50 }
51 }
52
53 if (!props.disableToast) {
54 displayToast(props.message || defaultLinkMessage, props);
55 }
56 } else {
57 displayToast(noLinkErrorMessage, props);
58 }
59
60 setCopying(true);
61 setTimeout(() => {
62 setCopying(false);
63 }, 1000);
64 };
65
66 return [copying, copy];
67}

Callers 1

codeFunction · 0.85

Calls 1

displayToastFunction · 0.85

Tested by

no test coverage detected