set display checkboxes (todo widescreen, refresh)

This commit is contained in:
Matt Walsh
2024-04-12 00:03:21 -05:00
parent 941bcacfad
commit eb69df8b80
3 changed files with 19 additions and 7 deletions

View File

@@ -4,7 +4,7 @@ import {
message as navMessage, isPlaying, resize, resetStatuses, latLonReceived, stopAutoRefreshTimer, registerRefreshData, message as navMessage, isPlaying, resize, resetStatuses, latLonReceived, stopAutoRefreshTimer, registerRefreshData,
} from './modules/navigation.mjs'; } from './modules/navigation.mjs';
import { round2 } from './modules/utils/units.mjs'; import { round2 } from './modules/utils/units.mjs';
import { readLink } from './modules/share.mjs'; import { parseQueryString } from './modules/share.mjs';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
init(); init();
@@ -83,7 +83,7 @@ const init = () => {
}; };
// attempt to parse the url parameters // attempt to parse the url parameters
const parsedParameters = readLink(); const parsedParameters = parseQueryString();
const loadFromParsed = parsedParameters.latLonQuery && parsedParameters.latLon; const loadFromParsed = parsedParameters.latLonQuery && parsedParameters.latLon;

View File

@@ -43,12 +43,16 @@ const createLink = async (e) => {
} }
}; };
const readLink = () => { const parseQueryString = () => {
// return memoized result
if (parseQueryString.params) return parseQueryString.params;
const urlSearchParams = new URLSearchParams(window.location.search); const urlSearchParams = new URLSearchParams(window.location.search);
return Object.fromEntries(urlSearchParams.entries()); // memoize result
parseQueryString.params = Object.fromEntries(urlSearchParams.entries());
return parseQueryString.params;
}; };
export { export {
createLink, createLink,
readLink, parseQueryString,
}; };

View File

@@ -5,6 +5,7 @@ import { DateTime } from '../vendor/auto/luxon.mjs';
import { import {
msg, displayNavMessage, isPlaying, updateStatus, timeZone, msg, displayNavMessage, isPlaying, updateStatus, timeZone,
} from './navigation.mjs'; } from './navigation.mjs';
import { parseQueryString } from './share.mjs';
class WeatherDisplay { class WeatherDisplay {
constructor(navId, elemId, name, defaultEnabled) { constructor(navId, elemId, name, defaultEnabled) {
@@ -50,8 +51,15 @@ class WeatherDisplay {
// no checkbox if progress // no checkbox if progress
if (this.elemId === 'progress') return false; if (this.elemId === 'progress') return false;
// get the saved status of the checkbox // get url provided state
let savedStatus = window.localStorage.getItem(`display-enabled: ${this.elemId}`); const urlValue = parseQueryString()?.[`${this.elemId}-checkbox`];
let urlState;
if (urlValue !== undefined) {
urlState = urlValue === 'true';
}
// get the saved status of the checkbox, but defer to a value set in the url
let savedStatus = urlState ?? window.localStorage.getItem(`display-enabled: ${this.elemId}`);
if (savedStatus === null) savedStatus = defaultEnabled; if (savedStatus === null) savedStatus = defaultEnabled;
this.isEnabled = !!((savedStatus === 'true' || savedStatus === true)); this.isEnabled = !!((savedStatus === 'true' || savedStatus === true));