]> git.immae.eu Git - github/bastienwirtz/homer.git/commitdiff
Implementing settings persistence. 3/head
authorBastien Wirtz <bastien.wirtz@gmail.com>
Tue, 8 Oct 2019 05:32:30 +0000 (22:32 -0700)
committerBastien Wirtz <bastien.wirtz@gmail.com>
Tue, 8 Oct 2019 05:32:30 +0000 (22:32 -0700)
app.js
index.html

diff --git a/app.js b/app.js
index a404314df8f8911597fb9dd72c1d7e1056f04fd7..41bdd9d40d911965b4b382ccb43abd493bffc962 100644 (file)
--- 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; 
+        }, 
     }
 });
 
index d5aebd30e64dbb05cfbcc1bd54fcf0d70062a260..1883223d73002e5ffd27780d23d006497914e1d2 100644 (file)
 </head>
 
 <body>
-  <div id="app" v-if="config" :class="{
-    'is-dark': overrideDark === true,
-    'is-light': overrideDark === false
-  }">
+  <div id="app" v-if="config" :class="[isDark ? 'is-dark' : 'is-light']">
     <div id="bighead">
       <section class="first-line">
         <div v-cloak class="container">
@@ -47,7 +44,7 @@
                     aria-label="Toggle dark mode"
                     ><i class="fas fa-adjust"></i>
                 </a>
-                <a v-on:click="vlayout = !vlayout" class="icon-button navbar-item"><i
+                <a v-on:click="toggleLayout()" class="icon-button navbar-item"><i
                     :class="['fas', vlayout ? 'fa-list' : 'fa-columns']"></i></a>
                 <div class="search-bar">
                   <label for="search" class="search-label"></label>