Fix copy link functionality

This commit is contained in:
gpt-engineer-app[bot] 2025-08-22 11:17:43 +00:00
parent ae5c1544ff
commit eb41d56dc0

View file

@ -55,15 +55,47 @@ const SocialShare: React.FC<SocialShareProps> = ({
}
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",
});
}