Skip to content

Commit e4ee800

Browse files
committed
Copy link on modal open
1 parent d1987a1 commit e4ee800

File tree

1 file changed

+21
-6
lines changed
  • src/components/basket/export-options

1 file changed

+21
-6
lines changed

src/components/basket/export-options/link.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {observer} from 'mobx-react-lite';
1616
import useStore from 'src/lib/state/context';
1717
import {type IPotentialFutureTerm} from 'src/lib/types';
1818
import Link from 'next/link';
19+
import {useEffect} from 'react';
1920

2021
type ExportLinkProps = {
2122
isOpen: boolean;
@@ -49,16 +50,30 @@ const ExportLink = observer(({isOpen, onClose}: ExportLinkProps) => {
4950

5051
const handleLinkCopy = async () => {
5152
if (url.length > 0) {
52-
await navigator.clipboard.writeText(url);
53+
try {
54+
await navigator.clipboard.writeText(url);
5355

54-
toast({
55-
title: 'Link Copied',
56-
status: 'success',
57-
duration: 500,
58-
});
56+
toast({
57+
title: 'Link Copied',
58+
status: 'success',
59+
duration: 500,
60+
});
61+
} catch (error) {
62+
console.error('Failed to copy link to clipboard:', error);
63+
}
5964
}
6065
};
6166

67+
useEffect(() => {
68+
const copyOnOpen = async () => {
69+
if (isOpen) {
70+
await handleLinkCopy();
71+
}
72+
};
73+
74+
void copyOnOpen();
75+
}, [isOpen]);
76+
6277
return (
6378
<>
6479
<Modal

0 commit comments

Comments
 (0)