From ed29ccf7eb2147c3bb28ab559be5cd0e0a3eab2f Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 15 Dec 2021 08:55:22 +0000 Subject: [PATCH] Pass current state to peek modals when opening them via query param --- packages/client/src/components/Router.svelte | 28 +++++++++++++++----- packages/client/src/stores/peek.js | 8 ++++-- packages/client/src/stores/state.js | 5 +++- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/packages/client/src/components/Router.svelte b/packages/client/src/components/Router.svelte index 95f52236a4..49cbc3f821 100644 --- a/packages/client/src/components/Router.svelte +++ b/packages/client/src/components/Router.svelte @@ -1,8 +1,9 @@ {#key config.id} diff --git a/packages/client/src/stores/peek.js b/packages/client/src/stores/peek.js index df41f5daff..83974b09f3 100644 --- a/packages/client/src/stores/peek.js +++ b/packages/client/src/stores/peek.js @@ -1,4 +1,5 @@ -import { writable } from "svelte/store" +import { writable, get } from "svelte/store" +import { stateStore } from "./state.js" const initialState = { showPeek: false, @@ -14,7 +15,10 @@ const createPeekStore = () => { let href = url let external = !url.startsWith("/") if (!external) { - href = `${window.location.href.split("#")[0]}#${url}?peek=true` + const state = get(stateStore) + const serialised = encodeURIComponent(btoa(JSON.stringify(state))) + const query = `peek=true&state=${serialised}` + href = `${window.location.href.split("#")[0]}#${url}?${query}` } store.set({ showPeek: true, diff --git a/packages/client/src/stores/state.js b/packages/client/src/stores/state.js index ce977c4333..4ad31c3854 100644 --- a/packages/client/src/stores/state.js +++ b/packages/client/src/stores/state.js @@ -34,6 +34,9 @@ const createStateStore = () => { }) } + // Initialises the temporary state store with a certain value + const initialise = tempStore.set + // Derive the combination of both persisted and non persisted stores const store = derived( [tempStore, persistentStore], @@ -47,7 +50,7 @@ const createStateStore = () => { return { subscribe: store.subscribe, - actions: { setValue, deleteValue }, + actions: { setValue, deleteValue, initialise }, } }