Skip to content

Commit

Permalink
comments, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanharikr committed Jun 28, 2024
1 parent b124fef commit b05b37b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -145,8 +147,6 @@
darkMode = false;
}
});
onMountDone = true;
});
const navLinks = [
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b05b37b

Please sign in to comment.