commit 61e87f2681acc0e5fa494859dcb51c1e6b8afc14
parent e7473dbbff9c83dfcacbbffe4cfc2eae35d89fcb
Author: Katja Ramona Sophie Kwast (zaphyra) <git@zaphyra.eu>
Date: Tue, 6 Jan 2026 18:31:50 +0100
parent e7473dbbff9c83dfcacbbffe4cfc2eae35d89fcb
Author: Katja Ramona Sophie Kwast (zaphyra) <git@zaphyra.eu>
Date: Tue, 6 Jan 2026 18:31:50 +0100
settings, searchView: fix product selection/initialisation
2 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/src/searchView.js b/src/searchView.js @@ -255,9 +255,9 @@ class SearchView extends BaseView { (product) => html` <input type="checkbox" - name="${product.id}" + name="products.${product.id}" id="${product.id}" - @click=${() => this.settingsState.toggleProduct(product.id)} + @change=${this.changeHandler} .checked=${this.settingsState.products[product.id] ?? true} /> <label @@ -692,11 +692,15 @@ class SearchView extends BaseView { const name = event.target.name; const value = event.target.value; - if (name === "noTransfers") this.noTransfers = !this.noTransfers; - if (name === "isArrival") this.isArrival = !this.isArrival; - if (name === "dateTime") this.date.setDateTime(value); - if (name === "date") this.date.setDate(value); - if (name === "time") this.date.setTime(value); + switch (name) { + case "noTransfers": this.noTransfers = !this.noTransfers; + case "isArrival": this.isArrival = !this.isArrival; + case "dateTime": this.date.setDateTime(value); + case "date": this.date.setDate(value); + case "time": this.date.setTime(value); + } + + if (name.startsWith("products")) this.settingsState.setProduct(name.slice(9), event.target.checked); this.requestUpdate(); };
diff --git a/src/settings.js b/src/settings.js @@ -28,13 +28,11 @@ export const initSettings = async () => { subscribers.add(callback); return () => subscribers.delete(callback); }}, - toggleProduct: { - value: product => { - let products = state.products; - products[product] = !products[product]; - localStorage[`products.${product}`] = JSON.stringify(products[product]); - state.products = products; - }, + setProduct: { + value: (product, value) => settings.setProducts({ + ...state.products, + [product]: value, + }), }, }; @@ -56,12 +54,15 @@ export const initSettings = async () => { enumerable: true, get: () => state[key], set: newValue => { - state[key] = newValue; if (typeof newValue === 'object') { Object.keys(newValue).forEach(objKey => { + if (newValue[objKey] === state[key][objKey]) return; + + state[key][objKey] = newValue[objKey]; localStorage[`${key}.${objKey}`] = JSON.stringify(newValue[objKey]); }); } else { + state[key] = newValue; localStorage[key] = JSON.stringify(newValue); } subscribers.forEach(callback => callback(settings));