diff --git a/src/lib/Util/state.ts b/src/lib/Util/state.ts index 4f95dc6f..463154b4 100644 --- a/src/lib/Util/state.ts +++ b/src/lib/Util/state.ts @@ -1,4 +1,4 @@ -import { writable, get } from 'svelte/store'; +import { writable, get, derived } from 'svelte/store'; import { toBase64, fromBase64 } from 'js-base64'; import { persist, localStorage } from '@macfja/svelte-persistent-store'; @@ -19,6 +19,9 @@ const defaultState: State = { }; export const codeStore = persist(writable(defaultState), localStorage(), 'codeStore'); +export const base64State = derived([codeStore], ([code], set) => { + set(toBase64(JSON.stringify(code), true)); +}); export const loadState = (data: string): void => { let state: State; @@ -50,8 +53,8 @@ export const updateConfig = (config: string, updateEditor: boolean): void => { }; export const initURLSubscription = (): void => { - codeStore.subscribe((state: State) => { - window.location.hash = toBase64(JSON.stringify(state), true); + base64State.subscribe((state: string) => { + window.location.hash = state; }); }; diff --git a/src/lib/components/history/index.svelte b/src/lib/components/history/index.svelte index 4d4e7367..59b2837c 100644 --- a/src/lib/components/history/index.svelte +++ b/src/lib/components/history/index.svelte @@ -63,11 +63,10 @@ -
+
-
{ + await goto(`/view#${$base64State}`, { replaceState: true }); + }; onMount(initHandler); @@ -102,9 +112,8 @@
-
+
-
{#if !$codeStore.autoSync} +
diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 6ff0f6c0..7fd08364 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -8,6 +8,7 @@ if (hash.length > 2) { newURL = `/${hash[1]}#${hash[2]}`; } + debugger; await goto(newURL, { replaceState: true });