From 5eda7ae889ef54b88508efe86c5606082940cd58 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 29 Nov 2022 18:07:12 +0100 Subject: [PATCH] noteify interface Use write callback to wait for reload --- apps/noteify/interface.html | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/apps/noteify/interface.html b/apps/noteify/interface.html index 027c98860..4d7974ad9 100644 --- a/apps/noteify/interface.html +++ b/apps/noteify/interface.html @@ -18,6 +18,11 @@ var notesElement = document.getElementById("notes"); var notes = {}; +function disableFormInput() { + document.querySelectorAll(".form-input").forEach(el => el.disabled = true); + document.querySelectorAll(".btn").forEach(el => el.disabled = true); +} + function getData() { // show loading window Util.showModal("Loading..."); @@ -53,8 +58,10 @@ function getData() { buttonSave.classList.add('btn-default'); buttonSave.onclick = function() { notes[i].note = textarea.value; - Util.writeStorage("noteify.json", JSON.stringify(notes)); - location.reload(); + disableFormInput(); + Util.writeStorage("noteify.json", JSON.stringify(notes), () => { + location.reload(); // reload so we see current data + }); } divColumn2.appendChild(buttonSave); @@ -64,8 +71,10 @@ function getData() { buttonDelete.onclick = function() { notes[i].note = textarea.value; notes.splice(i, 1); - Util.writeStorage("noteify.json", JSON.stringify(notes)); - location.reload(); // reload so we see current data + disableFormInput(); + Util.writeStorage("noteify.json", JSON.stringify(notes), () => { + location.reload(); // reload so we see current data + }); } divColumn2.appendChild(buttonDelete); divColumn.appendChild(divColumn2); @@ -77,8 +86,10 @@ function getData() { document.getElementById("btnAdd").addEventListener("click", function() { const note = document.getElementById("note-new").value; notes.push({"note": note}); - Util.writeStorage("noteify.json", JSON.stringify(notes)); - location.reload(); // reload so we see current data + disableFormInput(); + Util.writeStorage("noteify.json", JSON.stringify(notes), () => { + location.reload(); // reload so we see current data + }); }); }); }