Merge branch 'main' into uzu

This commit is contained in:
Felix Roos 2025-06-18 21:26:51 +02:00
commit 28cd7c1681
No known key found for this signature in database
186 changed files with 3188 additions and 2138 deletions

View file

@ -7,7 +7,7 @@ import './Repl.css';
import { createClient } from '@supabase/supabase-js';
import { nanoid } from 'nanoid';
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
import { $featuredPatterns, loadDBPatterns } from '@src/user_pattern_utils.mjs';
import { $featuredPatterns /* , loadDBPatterns */ } from '@src/user_pattern_utils.mjs';
// Create a single supabase client for interacting with your database
export const supabase = createClient(
@ -16,9 +16,9 @@ export const supabase = createClient(
);
let dbLoaded;
if (typeof window !== 'undefined') {
/* if (typeof window !== 'undefined') {
dbLoaded = loadDBPatterns();
}
} */
export async function initCode() {
// load code from url hash (either short hash from database or decode long hash)
@ -110,38 +110,56 @@ export function confirmDialog(msg) {
}
let lastShared;
export async function shareCode(codeToShare) {
// const codeToShare = activeCode || code;
if (lastShared === codeToShare) {
logger(`Link already generated!`, 'error');
return;
}
confirmDialog(
'Do you want your pattern to be public? If no, press cancel and you will get just a private link.',
).then(async (isPublic) => {
const hash = nanoid(12);
const shareUrl = window.location.origin + window.location.pathname + '?' + hash;
const { error } = await supabase.from('code_v1').insert([{ code: codeToShare, hash, ['public']: isPublic }]);
if (!error) {
lastShared = codeToShare;
// copy shareUrl to clipboard
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');
//RIP due to SPAM
// export async function shareCode(codeToShare) {
// // const codeToShare = activeCode || code;
// if (lastShared === codeToShare) {
// logger(`Link already generated!`, 'error');
// return;
// }
// confirmDialog(
// 'Do you want your pattern to be public? If no, press cancel and you will get just a private link.',
// ).then(async (isPublic) => {
// const hash = nanoid(12);
// const shareUrl = window.location.origin + window.location.pathname + '?' + hash;
// const { error } = await supabase.from('code_v1').insert([{ code: codeToShare, hash, ['public']: isPublic }]);
// if (!error) {
// lastShared = codeToShare;
// // copy shareUrl to clipboard
// 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 {
console.log('error', error);
const message = `Error: ${error.message}`;
// alert(message);
logger(message);
await navigator.clipboard.writeText(shareUrl);
}
});
const message = `Link copied to clipboard!`;
alert(message);
logger(message, 'highlight');
} catch (e) {
console.error(e);
}
}
export const isIframe = () => window.location !== window.parent.location;