From 67305ad08441b309aa52c0002ead5623cc337f77 Mon Sep 17 00:00:00 2001 From: Parnic Date: Fri, 23 Apr 2021 08:00:07 -0500 Subject: [PATCH] Fix manually-checked chores un-checking on refresh I forgot to account for saving the data on the frontend, so it was only ever using whatever the last data passed to us from the backend was, which only happens once on initial load. --- MMM-chores.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/MMM-chores.js b/MMM-chores.js index 89c4f9b..2fb38b1 100644 --- a/MMM-chores.js +++ b/MMM-chores.js @@ -52,12 +52,8 @@ Module.register("MMM-chores", { socketNotificationReceived(notification, payload) { if (notification === "CHORES_DATA_READ") { - for (const v in payload) { - const elem = document.getElementById(v) - if (elem) { - elem.checked = payload[v] === 1 - } - } + this.saved_data = payload + this.updateDom() } }, @@ -83,9 +79,14 @@ Module.register("MMM-chores", { if (id !== undefined) { cb.id = id } + cb.checked = this.saved_data && this.saved_data[cb.id] === 1 cb.onclick = (ev) => { let targetId = ev.target.id let val = cb.checked ? 1 : 0 + if (!this.saved_data) { + this.saved_data = {} + } + this.saved_data[targetId] = val this.sendSocketNotification("CHORES_ADD_DATA", { "key": targetId, "val": val }) const numItems = 2