mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 21:58:37 +00:00
ask for public sharing (very cheap) + order browse list
This commit is contained in:
parent
3c1844046a
commit
1ede99f71e
@ -8,7 +8,7 @@ function PatternLink({ pattern }: { pattern: Tables<'code'> }) {
|
||||
// console.log('meta', meta);
|
||||
return (
|
||||
<a href={`/?${pattern.hash}`} target="_blank">
|
||||
{meta.title || pattern.hash} by {meta.by.join(',') || 'Anonymous'}
|
||||
{pattern.id}. {meta.title || pattern.hash} by {meta.by.join(',') || 'Anonymous'}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
@ -21,8 +21,18 @@ export function SharedPatterns() {
|
||||
'https://pidxdsxphlhzjnzmifth.supabase.co',
|
||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InBpZHhkc3hwaGxoempuem1pZnRoIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NTYyMzA1NTYsImV4cCI6MTk3MTgwNjU1Nn0.bqlw7802fsWRnqU5BLYtmXk_k-D1VFmbkHMywWc15NM',
|
||||
);
|
||||
const { data: _publicPatterns } = await supabase.from('code').select().eq('public', true).limit(20);
|
||||
const { data: _featuredPatterns } = await supabase.from('code').select().eq('featured', true).limit(20);
|
||||
const { data: _publicPatterns } = await supabase
|
||||
.from('code')
|
||||
.select()
|
||||
.eq('public', true)
|
||||
.limit(20)
|
||||
.order('id', { ascending: false });
|
||||
const { data: _featuredPatterns } = await supabase
|
||||
.from('code')
|
||||
.select()
|
||||
.eq('featured', true)
|
||||
.limit(20)
|
||||
.order('id', { ascending: false });
|
||||
setPublicPatterns(_publicPatterns);
|
||||
setFeaturedPatterns(_featuredPatterns);
|
||||
/* console.log('public', publicPatterns);
|
||||
|
||||
@ -90,10 +90,13 @@ export async function shareCode(codeToShare) {
|
||||
logger(`Link already generated!`, 'error');
|
||||
return;
|
||||
}
|
||||
const isPublic = confirm(
|
||||
'Do you want your pattern to be public? If no, press cancel and you will get just a private link.',
|
||||
);
|
||||
// generate uuid in the browser
|
||||
const hash = nanoid(12);
|
||||
const shareUrl = window.location.origin + window.location.pathname + '?' + hash;
|
||||
const { data, error } = await supabase.from('code').insert([{ code: codeToShare, hash }]);
|
||||
const { error } = await supabase.from('code').insert([{ code: codeToShare, hash, ['public']: isPublic }]);
|
||||
if (!error) {
|
||||
lastShared = codeToShare;
|
||||
// copy shareUrl to clipboard
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user