From c11eeb5cd95e5955c1822211dc78000d03d82e7c Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 10 Sep 2024 10:15:05 +0200 Subject: [PATCH] feat(ceremony): save auto --- ceremony/src/lib/stores/persisted.ts | 21 +++++++++++++++++++++ ceremony/src/routes/app/+page.svelte | 15 ++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 ceremony/src/lib/stores/persisted.ts diff --git a/ceremony/src/lib/stores/persisted.ts b/ceremony/src/lib/stores/persisted.ts new file mode 100644 index 0000000000..971fbe1c99 --- /dev/null +++ b/ceremony/src/lib/stores/persisted.ts @@ -0,0 +1,21 @@ +import { writable } from "svelte/store" + +export function persistedWritable(key: string, data: T) { + const { subscribe, set, update } = writable(data) + const isBrowser = typeof window !== "undefined" + + return { + set, + update, + subscribe, + useLocalStorage: () => { + const json = localStorage.getItem(key) + if (!json) return + if (json) set(JSON.parse(json) as T) + + subscribe(current => { + localStorage.setItem(key, JSON.stringify(current)) + }) + } + } +} diff --git a/ceremony/src/routes/app/+page.svelte b/ceremony/src/routes/app/+page.svelte index ce8412a97b..c87c986d1d 100644 --- a/ceremony/src/routes/app/+page.svelte +++ b/ceremony/src/routes/app/+page.svelte @@ -42,6 +42,19 @@ let {data: contribute, isLoading: contributeLoading, error: contributeError} = $derived($contributionQuery) let {data: client, isLoading: clientLoading, error: clientError} = $derived($clientQuery) + //TODO SAVE IN LOCAL STORAGE AND ADD INFO TEXT ABOUT HAVING THE BROWSER OPEN + let auto = $state(false) + + $effect(() => { + if(auto) { + if(contribute?.canContribute && contribute?.shouldContribute) { + if (client) { + start() + } + } + } + }) + @@ -71,11 +84,11 @@ {:else if client} {client.status} -

You can contribute

{:else} Waiting for client... {/if} + Auto contribute {:else if contribute?.isVerifying}