Spaces:
Running
Running
web share API
Browse files- pages/index.js +18 -0
pages/index.js
CHANGED
|
@@ -92,6 +92,24 @@ export default function Home() {
|
|
| 92 |
}
|
| 93 |
} else {
|
| 94 |
setIsCapturingGif(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
}
|
| 96 |
};
|
| 97 |
|
|
|
|
| 92 |
}
|
| 93 |
} else {
|
| 94 |
setIsCapturingGif(false);
|
| 95 |
+
// Get the generated GIF file
|
| 96 |
+
const gifFile = document.querySelector('a[download="word-to-code-animation.gif"]');
|
| 97 |
+
if (gifFile && navigator.share) {
|
| 98 |
+
try {
|
| 99 |
+
const response = await fetch(gifFile.href);
|
| 100 |
+
const blob = await response.blob();
|
| 101 |
+
const file = new File([blob], 'animation.gif', { type: 'image/gif' });
|
| 102 |
+
await navigator.share({
|
| 103 |
+
title: 'Word to Code Animation',
|
| 104 |
+
text: 'Check out this animation I created!',
|
| 105 |
+
files: [file]
|
| 106 |
+
});
|
| 107 |
+
} catch (error) {
|
| 108 |
+
console.error('Error sharing:', error);
|
| 109 |
+
// If sharing fails, fallback to normal download
|
| 110 |
+
gifFile.click();
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
}
|
| 114 |
};
|
| 115 |
|