From 351e1a20b16989f21c8bad26920312a5d02ff3c0 Mon Sep 17 00:00:00 2001 From: Niko Date: Mon, 14 Feb 2022 16:55:26 +0100 Subject: [PATCH] Add app.storage wrapper for handling localStorage --- web/src/app/js/app.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/web/src/app/js/app.js b/web/src/app/js/app.js index 56d925f..2930c7d 100644 --- a/web/src/app/js/app.js +++ b/web/src/app/js/app.js @@ -84,6 +84,25 @@ app.template = { }, } +app.storage = { + _init: function() { + if (localStorage['fedilove'] === undefined) + localStorage['fedilove'] = '{}'; + }, + get: function(key) { + app.storage._init(); + const js = JSON.parse(localStorage['fedilove']); + return js[key]; + }, + set: function(key, value) { + app.storage._init(); + const js = JSON.parse(localStorage['fedilove']); + js[key] = value; + localStorage['fedilove'] = JSON.stringify(js); + return true; + }, +}; + app.overlay = { hideAll: function() { document.querySelectorAll('.overlay')