From: Bastien Wirtz Date: Tue, 8 Oct 2019 05:32:30 +0000 (-0700) Subject: Implementing settings persistence. X-Git-Tag: v1.0~20^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=d6adb2db1b20fcd3e1ad50bfab8324d0ab2f714f;p=github%2Fbastienwirtz%2Fhomer.git Implementing settings persistence. --- 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" > -