summaryrefslogtreecommitdiff
path: root/static/js
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-27 19:53:04 -0600
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-27 19:53:04 -0600
commitb6e8e041096a921accd439db00c9171c0f68d91b (patch)
treee4c58632b8956de12d249f99e0836138a6028655 /static/js
parent68f3bd53328606a921dd72870f38723286d803e1 (diff)
downloadhatecomputers.club-b6e8e041096a921accd439db00c9171c0f68d91b.tar.gz
hatecomputers.club-b6e8e041096a921accd439db00c9171c0f68d91b.zip
use media queries
Diffstat (limited to 'static/js')
-rw-r--r--static/js/components/themeSwitcher.js2
-rw-r--r--static/js/util/setThemeBeforeRender.js10
2 files changed, 7 insertions, 5 deletions
diff --git a/static/js/components/themeSwitcher.js b/static/js/components/themeSwitcher.js
index 5f6d927..e5497f0 100644
--- a/static/js/components/themeSwitcher.js
+++ b/static/js/components/themeSwitcher.js
@@ -24,4 +24,4 @@ themeSwitcher.addEventListener("click", () =>
setTheme(flipFlopTheme(document.documentElement.getAttribute("data-theme"))),
);
-setTheme(localStorage.getItem("theme") ?? THEMES.LIGHT);
+setTheme(localStorage.getItem("theme") || THEMES.LIGHT);
diff --git a/static/js/util/setThemeBeforeRender.js b/static/js/util/setThemeBeforeRender.js
index d826193..b8f299a 100644
--- a/static/js/util/setThemeBeforeRender.js
+++ b/static/js/util/setThemeBeforeRender.js
@@ -1,6 +1,8 @@
+const preferredMode = window.matchMedia("(prefers-color-scheme: dark)").matches
+ ? "DARK"
+ : "LIGHT";
+localStorage.setItem("theme", localStorage.getItem("theme") || preferredMode);
+
// sets theme before rendering & jquery loaded to prevent flashing of uninitialized theme
// (ugly white background)
-document.documentElement.setAttribute(
- "data-theme",
- localStorage.getItem("theme"),
-);
+document.documentElement.setAttribute("data-theme", preferredMode);