File tree Expand file tree Collapse file tree 1 file changed +21
-6
lines changed
src/components/basket/export-options Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import {observer} from 'mobx-react-lite';
1616import useStore from 'src/lib/state/context' ;
1717import { type IPotentialFutureTerm } from 'src/lib/types' ;
1818import Link from 'next/link' ;
19+ import { useEffect } from 'react' ;
1920
2021type 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
You can’t perform that action at this time.
0 commit comments