parse settings from querystring

This commit is contained in:
Matt Walsh
2024-04-19 21:05:52 -05:00
parent 5d0f41f207
commit 6d4ec8b958
3 changed files with 16 additions and 2 deletions

View File

@@ -1,3 +1,5 @@
import { parseQueryString } from '../share.mjs';
const SETTINGS_KEY = 'Settings';
class Setting {
@@ -9,10 +11,17 @@ class Setting {
this.myValue = defaultValue;
this.type = type;
// a default blank change function is provided
this.changeAction = changeAction ?? (() => {});
this.changeAction = changeAction ?? (() => { });
// get value from url
const urlValue = parseQueryString()?.[`settings-${shortName}-checkbox`];
let urlState;
if (urlValue !== undefined) {
urlState = urlValue === 'true';
}
// get existing value if present
const storedValue = this.getFromLocalStorage();
const storedValue = urlState ?? this.getFromLocalStorage();
if (sticky && storedValue !== null) {
this.myValue = storedValue;
}