From b05b37b0c5b6aa349f299a7e3e57f0fa84a18340 Mon Sep 17 00:00:00 2001 From: rohanharikr Date: Fri, 28 Jun 2024 11:55:50 +0100 Subject: [PATCH] comments, refactor --- src/App.svelte | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index b9c0be8..170d27f 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -4,7 +4,7 @@ import Prism from "svelte-prism"; import makePKCE from "./utils/pkce.js"; - let onMountDone = false; + let readFromLocalStorage = false; let darkMode = false; const scopes = { @@ -87,8 +87,10 @@ onMount(() => { if(!getStatesFromLocalStorage()) { //states not found in local storage, save default states to local storage - states = states; //triggers saveStatesToLocalStorage + const _states = JSON.stringify(states); + localStorage.setItem("states", _states); } + readFromLocalStorage = true; processFragmentOrQuery(); updateFavicon(); @@ -145,8 +147,6 @@ darkMode = false; } }); - - onMountDone = true; }); const navLinks = [ @@ -498,7 +498,12 @@ } function saveStatesToLocalStorage() { - if (!onMountDone) return; + if (!readFromLocalStorage) { + //only update states in localStorage after reading from it on onMount + //if not, states gets reset on every page load (we need to update on existing localstorage state) + return; + } + const _states = JSON.stringify(states); localStorage.setItem("states", _states); }