From eb41d56dc0d99ecd3086b1e7120cd61c8b62051d Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Fri, 22 Aug 2025 11:17:43 +0000 Subject: [PATCH] Fix copy link functionality --- src/components/SocialShare.tsx | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/components/SocialShare.tsx b/src/components/SocialShare.tsx index 7f3cf60..c332c23 100644 --- a/src/components/SocialShare.tsx +++ b/src/components/SocialShare.tsx @@ -55,15 +55,47 @@ const SocialShare: React.FC = ({ } try { + // Check if clipboard API is available + if (!navigator.clipboard) { + // Fallback for older browsers or insecure contexts + const textArea = document.createElement('textarea'); + textArea.value = text; + textArea.style.position = 'fixed'; + textArea.style.left = '-999999px'; + textArea.style.top = '-999999px'; + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + + try { + document.execCommand('copy'); + toast({ + title: "Copied!", + description: "Link copied to clipboard", + }); + } catch (err) { + console.error('Fallback copy failed:', err); + toast({ + title: "Error", + description: "Failed to copy to clipboard", + variant: "destructive", + }); + } finally { + document.body.removeChild(textArea); + } + return; + } + await navigator.clipboard.writeText(text); toast({ title: "Copied!", description: "Link copied to clipboard", }); } catch (err) { + console.error('Copy failed:', err); toast({ title: "Error", - description: "Failed to copy to clipboard", + description: "Failed to copy to clipboard. Please copy the URL manually.", variant: "destructive", }); }