@@ -109,38 +109,56 @@ export function confirmDialog(msg) {
109109}
110110
111111let lastShared ;
112- export async function shareCode ( codeToShare ) {
113- // const codeToShare = activeCode || code;
114- if ( lastShared === codeToShare ) {
115- logger ( `Link already generated!` , 'error' ) ;
116- return ;
117- }
118112
119- confirmDialog (
120- 'Do you want your pattern to be public? If no, press cancel and you will get just a private link.' ,
121- ) . then ( async ( isPublic ) => {
122- const hash = nanoid ( 12 ) ;
123- const shareUrl = window . location . origin + window . location . pathname + '?' + hash ;
124- const { error } = await supabase . from ( 'code_v1' ) . insert ( [ { code : codeToShare , hash, [ 'public' ] : isPublic } ] ) ;
125- if ( ! error ) {
126- lastShared = codeToShare ;
127- // copy shareUrl to clipboard
128- if ( isTauri ( ) ) {
129- await writeText ( shareUrl ) ;
130- } else {
131- await navigator . clipboard . writeText ( shareUrl ) ;
132- }
133- const message = `Link copied to clipboard: ${ shareUrl } ` ;
134- alert ( message ) ;
135- // alert(message);
136- logger ( message , 'highlight' ) ;
113+ //RIP due to SPAM
114+ // export async function shareCode(codeToShare) {
115+ // // const codeToShare = activeCode || code;
116+ // if (lastShared === codeToShare) {
117+ // logger(`Link already generated!`, 'error');
118+ // return;
119+ // }
120+
121+ // confirmDialog(
122+ // 'Do you want your pattern to be public? If no, press cancel and you will get just a private link.',
123+ // ).then(async (isPublic) => {
124+ // const hash = nanoid(12);
125+ // const shareUrl = window.location.origin + window.location.pathname + '?' + hash;
126+ // const { error } = await supabase.from('code_v1').insert([{ code: codeToShare, hash, ['public']: isPublic }]);
127+ // if (!error) {
128+ // lastShared = codeToShare;
129+ // // copy shareUrl to clipboard
130+ // if (isTauri()) {
131+ // await writeText(shareUrl);
132+ // } else {
133+ // await navigator.clipboard.writeText(shareUrl);
134+ // }
135+ // const message = `Link copied to clipboard: ${shareUrl}`;
136+ // alert(message);
137+ // // alert(message);
138+ // logger(message, 'highlight');
139+ // } else {
140+ // console.log('error', error);
141+ // const message = `Error: ${error.message}`;
142+ // // alert(message);
143+ // logger(message);
144+ // }
145+ // });
146+ // }
147+
148+ export async function shareCode ( ) {
149+ try {
150+ const shareUrl = window . location . href ;
151+ if ( isTauri ( ) ) {
152+ await writeText ( shareUrl ) ;
137153 } else {
138- console . log ( 'error' , error ) ;
139- const message = `Error: ${ error . message } ` ;
140- // alert(message);
141- logger ( message ) ;
154+ await navigator . clipboard . writeText ( shareUrl ) ;
142155 }
143- } ) ;
156+ const message = `Link copied to clipboard!` ;
157+ alert ( message ) ;
158+ logger ( message , 'highlight' ) ;
159+ } catch ( e ) {
160+ console . error ( e ) ;
161+ }
144162}
145163
146164export const isIframe = ( ) => window . location !== window . parent . location ;
0 commit comments