Skip to content
Snippets Groups Projects
Commit 51c800d3 authored by Pierre-Jean CHANCELLIER's avatar Pierre-Jean CHANCELLIER
Browse files

improve theme management

parent 593907f9
No related branches found
No related tags found
No related merge requests found
...@@ -12,8 +12,7 @@ ...@@ -12,8 +12,7 @@
<script> <script>
export default { export default {
mounted() { mounted() {
const initUserTheme = this.getMediaPreference(); this.setTheme(localStorage.getItem("user-theme"))
this.setTheme(initUserTheme);
}, },
data() { data() {
...@@ -24,23 +23,19 @@ export default { ...@@ -24,23 +23,19 @@ export default {
methods: { methods: {
toggleTheme() { toggleTheme() {
const activeTheme = localStorage.getItem("user-theme"); if (this.userTheme === "light-theme") {
if (activeTheme === "light-theme") { this.setTheme("dark-theme")
this.setTheme("dark-theme");
} else { } else {
this.setTheme("light-theme"); this.setTheme("light-theme")
} }
}, },
setTheme(theme) { setTheme(theme) {
localStorage.setItem("user-theme", theme); if (theme == null) {theme="light-theme"}
this.userTheme = theme; localStorage.setItem("user-theme", theme)
document.documentElement.className = theme; this.userTheme = theme
}, document.documentElement.className = theme
}
getMediaPreference() {
return localStorage.getItem("user-theme");
},
}, },
}; };
</script> </script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment