fix: copy button in share assets fix
Signed-off-by: Varun <varun@skcript.com>
This commit is contained in:
1 parent
f7fecd6b24
commit
11e88526c7
1 file changed
+17
-3
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user