diff --git a/src/app/pages/Generator.tsx b/src/app/pages/Generator.tsx index 5fc7fbd6..9c947d49 100644 --- a/src/app/pages/Generator.tsx +++ b/src/app/pages/Generator.tsx @@ -67,6 +67,10 @@ export function Generator({}: Props) { route(`${cleanUrl(snippetGen.url)}?${SHARE_KEY}=${snippet.id}`) } } + if (snippet.show_preview && !previewShown) { + setPreviewShown(true) + setSourceShown(false) + } model.reset(DataModel.wrapLists(snippet.data), false) } @@ -231,10 +235,10 @@ export function Generator({}: Props) { } else if (model && blockStates) { const output = getOutput(model, blockStates) if (deepEqual(output, model.schema.default())) { - setShareUrl(`${location.protocol}//${location.host}/${gen.url}/`) + setShareUrl(`${location.protocol}//${location.host}/${gen.url}/?version=${version}`) setShareShown(true) } else { - shareSnippet(gen.id, version, output) + shareSnippet(gen.id, version, output, previewShown) .then(url => { setShareUrl(url) setShareShown(true) diff --git a/src/app/services/Sharing.ts b/src/app/services/Sharing.ts index 8286d3cf..3739bdb7 100644 --- a/src/app/services/Sharing.ts +++ b/src/app/services/Sharing.ts @@ -7,12 +7,12 @@ export const SHARE_KEY = 'share' const ShareCache = new Map() -export async function shareSnippet(type: string, version: VersionId, jsonData: any) { +export async function shareSnippet(type: string, version: VersionId, jsonData: any, show_preview: boolean) { try { const data = lz.compressToBase64(JSON.stringify(jsonData)) const raw = btoa(JSON.stringify(jsonData)) console.log('Compression rate', raw.length / data.length) - const body = JSON.stringify({ data, type, version }) + const body = JSON.stringify({ data, type, version, show_preview }) let id = ShareCache.get(body) if (!id) { const snippet = await fetchApi('/snippets', body)