From d6adb2db1b20fcd3e1ad50bfab8324d0ab2f714f Mon Sep 17 00:00:00 2001 From: Bastien Wirtz Date: Mon, 7 Oct 2019 22:32:30 -0700 Subject: Implementing settings persistence. --- app.js | 25 +++++++++++++++---------- index.html | 7 ++----- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app.js b/app.js index a404314..41bdd9d 100644 --- a/app.js +++ b/app.js @@ -5,11 +5,18 @@ const app = new Vue({ offline: false, filter: '', vlayout: true, - overrideDark: null + isDark: null }, created: function () { let that = this; + + this.isDark = 'overrideDark' in localStorage ? + JSON.parse(localStorage.overrideDark) : matchMedia("(prefers-color-scheme: dark)").matches; + if ('vlayout' in localStorage) { + this.vlayout = JSON.parse(localStorage.vlayout) + } + this.checkOffline(); that.getConfig().then(function (config) { that.config = config; @@ -23,13 +30,6 @@ const app = new Vue({ } }, false); }, - computed: { - isDark: function() { - return this.overrideDark !== null - ? this.overrideDark - : matchMedia("(prefers-color-scheme: dark)").matches; - } - }, methods: { checkOffline: function () { let that = this; @@ -53,8 +53,13 @@ const app = new Vue({ }); }, toggleTheme: function() { - this.overrideDark = !this.isDark; - } + this.isDark = !this.isDark; + localStorage.overrideDark = this.isDark; + }, + toggleLayout: function() { + this.vlayout = !this.vlayout; + localStorage.vlayout = this.vlayout; + }, } }); diff --git a/index.html b/index.html index d5aebd3..1883223 100644 --- a/index.html +++ b/index.html @@ -14,10 +14,7 @@ -
+
@@ -47,7 +44,7 @@ aria-label="Toggle dark mode" > -