fix: copy button in share assets fix

Signed-off-by: Varun <varun@skcript.com>
This commit is contained in:
Varun committed 2026-04-06 19:16:04 +05:30
1 parent f7fecd6b24
commit 11e88526c7
1 file changed
+17 -3
+17 -3
View File
@@ -40,13 +40,27 @@ export default function ShareAssetsTrigger({ filters, buttonProps }: ShareAssets
});
}
const handleCopy = () => {
if (generatedLink) {
navigator.clipboard.writeText(generatedLink);
const handleCopy = async () => {
if (!generatedLink) return;
try {
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(generatedLink);
} else {
const textArea = document.createElement('textarea');
textArea.value = generatedLink;
textArea.style.position = 'fixed';
textArea.style.left = '-9999px';
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
}
setCopied(true);
setTimeout(() => {
setCopied(false);
}, 2000);
} catch {
setErrorMessage('Failed to copy link');
}
}