Merge pull request #1375 from tidalcycles/jade/share_fat

Share fat URL
This commit is contained in:
Jade (Rose) Rowland 2025-06-12 10:25:48 +02:00 committed by GitHub
commit c1fa5d0855
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 49 additions and 31 deletions

View file

@ -102,7 +102,7 @@ export function Header({ context, embedded = false }) {
<span> shuffle</span> <span> shuffle</span>
</button> </button>
) */} ) */}
{/* !isEmbedded && ( {!isEmbedded && (
<button <button
title="share" title="share"
className={cx( className={cx(
@ -113,7 +113,7 @@ export function Header({ context, embedded = false }) {
> >
<span>share</span> <span>share</span>
</button> </button>
) */} )}
{!isEmbedded && ( {!isEmbedded && (
<a <a
title="learn" title="learn"

View file

@ -109,38 +109,56 @@ export function confirmDialog(msg) {
} }
let lastShared; let lastShared;
export async function shareCode(codeToShare) {
// const codeToShare = activeCode || code;
if (lastShared === codeToShare) {
logger(`Link already generated!`, 'error');
return;
}
confirmDialog( //RIP due to SPAM
'Do you want your pattern to be public? If no, press cancel and you will get just a private link.', // export async function shareCode(codeToShare) {
).then(async (isPublic) => { // // const codeToShare = activeCode || code;
const hash = nanoid(12); // if (lastShared === codeToShare) {
const shareUrl = window.location.origin + window.location.pathname + '?' + hash; // logger(`Link already generated!`, 'error');
const { error } = await supabase.from('code_v1').insert([{ code: codeToShare, hash, ['public']: isPublic }]); // return;
if (!error) { // }
lastShared = codeToShare;
// copy shareUrl to clipboard // confirmDialog(
if (isTauri()) { // 'Do you want your pattern to be public? If no, press cancel and you will get just a private link.',
await writeText(shareUrl); // ).then(async (isPublic) => {
} else { // const hash = nanoid(12);
await navigator.clipboard.writeText(shareUrl); // const shareUrl = window.location.origin + window.location.pathname + '?' + hash;
} // const { error } = await supabase.from('code_v1').insert([{ code: codeToShare, hash, ['public']: isPublic }]);
const message = `Link copied to clipboard: ${shareUrl}`; // if (!error) {
alert(message); // lastShared = codeToShare;
// alert(message); // // copy shareUrl to clipboard
logger(message, 'highlight'); // if (isTauri()) {
// await writeText(shareUrl);
// } else {
// await navigator.clipboard.writeText(shareUrl);
// }
// const message = `Link copied to clipboard: ${shareUrl}`;
// alert(message);
// // alert(message);
// logger(message, 'highlight');
// } else {
// console.log('error', error);
// const message = `Error: ${error.message}`;
// // alert(message);
// logger(message);
// }
// });
// }
export async function shareCode() {
try {
const shareUrl = window.location.href;
if (isTauri()) {
await writeText(shareUrl);
} else { } else {
console.log('error', error); await navigator.clipboard.writeText(shareUrl);
const message = `Error: ${error.message}`;
// alert(message);
logger(message);
} }
}); const message = `Link copied to clipboard!`;
alert(message);
logger(message, 'highlight');
} catch (e) {
console.error(e);
}
} }
export const isIframe = () => window.location !== window.parent.location; export const isIframe = () => window.location !== window.parent.location;