mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 23:56:51 +00:00
Share if preview is shown
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -7,12 +7,12 @@ export const SHARE_KEY = 'share'
|
||||
|
||||
const ShareCache = new Map<string, string>()
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user