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 @@
<script>
export default {
mounted() {
const initUserTheme = this.getMediaPreference();
this.setTheme(initUserTheme);
this.setTheme(localStorage.getItem("user-theme"))
},
data() {
......@@ -24,23 +23,19 @@ export default {
methods: {
toggleTheme() {
const activeTheme = localStorage.getItem("user-theme");
if (activeTheme === "light-theme") {
this.setTheme("dark-theme");
if (this.userTheme === "light-theme") {
this.setTheme("dark-theme")
} else {
this.setTheme("light-theme");
this.setTheme("light-theme")
}
},
setTheme(theme) {
localStorage.setItem("user-theme", theme);
this.userTheme = theme;
document.documentElement.className = theme;
},
getMediaPreference() {
return localStorage.getItem("user-theme");
},
if (theme == null) {theme="light-theme"}
localStorage.setItem("user-theme", theme)
this.userTheme = theme
document.documentElement.className = theme
}
},
};
</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