Skip to content

Commit

Permalink
save states on load (#35)
Browse files Browse the repository at this point in the history
* save states on load

* fix
  • Loading branch information
rohanharikr authored Jun 27, 2024
1 parent 35ee908 commit b124fef
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@
}
onMount(() => {
getStatesFromLocalStorage();
if(!getStatesFromLocalStorage()) {
//states not found in local storage, save default states to local storage
states = states; //triggers saveStatesToLocalStorage
}
processFragmentOrQuery();
updateFavicon();
Expand Down Expand Up @@ -475,15 +479,18 @@
}
function getStatesFromLocalStorage() {
if (!localStorage.states) return;
if (!localStorage.states)
return false;
try {
const _states = JSON.parse(localStorage.getItem("states"));
if (!compareKeys(states, _states)) {
console.info("State keys do not match, clearing localStorage");
localStorage.removeItem("states");
return;
return false;
}
states = _states;
return true;
} catch (err) {
console.error(err);
localStorage.removeItem("states");
Expand Down

0 comments on commit b124fef

Please sign in to comment.