From e9ac9187757e2a027fe06fafec5248e9cfdf6c1b Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Thu, 15 Feb 2024 11:07:21 +0100 Subject: [PATCH] refactor index serialization --- main.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index aa658da..f825f60 100644 --- a/main.js +++ b/main.js @@ -1126,7 +1126,7 @@ function createnote(title) header: indexheader(content) }; metadata[guid] = item; - localStorage.setItem("index", JSON.stringify(metadata)); + serializeindex() localStorage.setItem(guid, content); return guid; } @@ -1811,7 +1811,7 @@ function serialize() item.header = indexheader(md.value); item.lastchanged = Date.now(); - localStorage.setItem("index", JSON.stringify(metadata)); + serializeindex() localStorage.setItem(guid, md.value); } else if (title.value == "settings.json") @@ -2375,18 +2375,23 @@ function restoredeleted() metadata[guid].deleted = false; metadata[guid].lastchanged = Date.now(); renameinternallinks(title + " (deleted)", title); - localStorage.setItem("index", JSON.stringify(metadata)); + serializeindex(); } }); } +function serializeindex() +{ + localStorage.setItem("index", JSON.stringify(metadata)); +} + function deletenote(title) { var guid = getguid(title); metadata[guid].deleted = true; metadata[guid].lastchanged = Date.now(); renameinternallinks(title, title + " (deleted)"); - localStorage.setItem("index", JSON.stringify(metadata)); + serializeindex() } function deletecurrentnote()