diff --git a/src/App.vue b/src/App.vue
index 69d75c8..69c47d4 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -55,10 +55,11 @@
-
@@ -102,7 +103,7 @@ export default defineComponent({
search: "",
chronosConfig: {} as ChronosConfig,
collectionShortName: "",
- isDarkMode: false,
+ theme: "system",
};
},
computed: {
@@ -117,6 +118,9 @@ export default defineComponent({
$route(to, from) {
this.fetchLanguages();
},
+ theme() {
+ this.applyTheme();
+ },
},
async mounted() {
try {
@@ -133,17 +137,9 @@ export default defineComponent({
state.prefLang = "en";
});
- // Dark mode
- const userPrefersDark =
- localStorage.getItem("darkMode") === "true" ||
- (!("darkMode" in localStorage) &&
- window.matchMedia("(prefers-color-scheme: dark)").matches);
- this.isDarkMode = userPrefersDark;
- if (userPrefersDark) {
- document.documentElement.classList.add("dark");
- } else {
- document.documentElement.classList.remove("dark");
- }
+ // Theme
+ this.theme = localStorage.getItem("theme") || "system";
+ this.applyTheme();
},
methods: {
setLang(lang: string) {
@@ -196,12 +192,29 @@ export default defineComponent({
}
}
},
-
- toggleDarkMode() {
- document.documentElement.classList.toggle("dark");
- const isDarkMode = document.documentElement.classList.contains("dark");
- localStorage.setItem("darkMode", isDarkMode ? "true" : "false");
- this.isDarkMode = isDarkMode;
+ applyTheme() {
+ if (this.theme === "system") {
+ if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
+ document.documentElement.classList.add("dark");
+ } else {
+ document.documentElement.classList.remove("dark");
+ }
+ } else if (this.theme === "dark") {
+ document.documentElement.classList.add("dark");
+ } else {
+ document.documentElement.classList.remove("dark");
+ }
+ },
+ toggleThemeMode() {
+ if (this.theme === "system") {
+ this.theme = "dark";
+ } else if (this.theme === "dark") {
+ this.theme = "light";
+ } else {
+ this.theme = "system";
+ }
+ localStorage.setItem("theme", this.theme);
+ this.applyTheme();
},
emptySearch() {
this.searchResponse = [];