Switch theme after loading for error pages
Some checks failed
/ Run tests (push) Successful in 1m34s
/ Run system tests (push) Failing after 1m52s
/ Build, push and deploy image (push) Successful in 1m17s

This commit is contained in:
david 2024-11-11 07:44:54 +01:00
parent 2b5d37295f
commit 375f72ec4d

View file

@ -6,12 +6,14 @@ export default class extends Controller {
COOKIE_NAME = "modeTheme";
connect() {
console.log("set theme")
const cookieValue = Cookie.get(this.COOKIE_NAME);
let darkMode = window.matchMedia("(prefers-color-scheme:dark)").matches ? "dark" : "light";
if (cookieValue) {
return true;
darkMode = cookieValue
} else {
Cookie.set(this.COOKIE_NAME, darkMode);
}
const darkMode = window.matchMedia("(prefers-color-scheme:dark)").matches ? "dark" : "light";
Cookie.set(this.COOKIE_NAME, darkMode);
window.document.getElementsByTagName("html")[0].setAttribute("data-bs-theme", darkMode)
}
}