From dfe32b93c0335c2f5d0d6233afee9257b3ad3c69 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Wed, 22 Sep 2021 12:05:25 +0530 Subject: [PATCH] fix: #381 URL mismatch --- src/lib/components/actions.svelte | 9 ++++----- src/lib/util/state.ts | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/components/actions.svelte b/src/lib/components/actions.svelte index bb418a58b5..d33010b7fd 100644 --- a/src/lib/components/actions.svelte +++ b/src/lib/components/actions.svelte @@ -2,8 +2,7 @@ import { browser } from '$app/env'; import Card from '$lib/components/card/card.svelte'; - import type { State } from '$lib/types'; - import { codeStore } from '$lib/util/state'; + import { base64State, codeStore } from '$lib/util/state'; import { toBase64 } from 'js-base64'; import moment from 'moment'; @@ -137,15 +136,15 @@ if (browser && ['mermaid.live', 'netlify'].some((path) => window.location.host.includes(path))) { isNetlify = true; } - codeStore.subscribe((state: State) => { - const stateCopy = JSON.parse(JSON.stringify(state)); + base64State.subscribe((encodedState: string) => { + const stateCopy = JSON.parse(JSON.stringify($codeStore)); if (typeof stateCopy.mermaid === 'string') { stateCopy.mermaid = JSON.parse(stateCopy.mermaid); } const b64Code = toBase64(JSON.stringify(stateCopy), true); iUrl = `https://mermaid.ink/img/${b64Code}`; svgUrl = `https://mermaid.ink/svg/${b64Code}`; - mdCode = `[![](${iUrl})](${window.location.protocol}//${window.location.host}${window.location.pathname}#${window.location.hash})`; + mdCode = `[![](${iUrl})](${window.location.protocol}//${window.location.host}${window.location.pathname}#${encodedState})`; }); diff --git a/src/lib/util/state.ts b/src/lib/util/state.ts index ee372ed2f3..5688493f15 100644 --- a/src/lib/util/state.ts +++ b/src/lib/util/state.ts @@ -1,4 +1,5 @@ import { writable, get, derived } from 'svelte/store'; +import type { Readable } from 'svelte/store'; import { toBase64, fromBase64 } from 'js-base64'; import { persist, localStorage } from '@macfja/svelte-persistent-store'; import type { State } from '$lib/types'; @@ -25,7 +26,7 @@ export const defaultState: State = { }; export const codeStore = persist(writable(defaultState), localStorage(), 'codeStore'); -export const base64State = derived([codeStore], ([code], set) => { +export const base64State: Readable = derived([codeStore], ([code], set) => { set(toBase64(JSON.stringify(code), true)); });