Skip to content

Commit

Permalink
feat(frontend): add persistent dark mode storage
Browse files Browse the repository at this point in the history
Closes #52
  • Loading branch information
ravenclaw900 committed Nov 21, 2021
1 parent e13faf7 commit 87b9366
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,21 @@
let shown = false;
let menu = window.innerWidth > 768;
let update = "";
let darkMode = window.matchMedia("(prefers-color-scheme: dark)").matches;
let darkMode = false;
let blur = false;
let navPage = "";
let token = "";
let password = "";
let login = false;
let loginDialog = false;
// Get dark mode
if (localStorage.getItem("darkMode") != null) {
darkMode = JSON.parse(localStorage.getItem("darkMode"));
} else {
darkMode = window.matchMedia("(prefers-color-scheme: dark)").matches;
}
const socketMessageListener = (e) => {
if (typeof e.data === "string") {
socketData = JSON.parse(e.data);
Expand Down Expand Up @@ -287,8 +294,10 @@
{/if}
<span
class="cursor-pointer justify-self-end mr-2"
on:click={() => (darkMode = !darkMode)}
><Fa icon={darkMode ? faMoon : faSun} size="lg" /></span
on:click={() => (
(darkMode = !darkMode),
localStorage.setItem("darkMode", darkMode.toString())
)}><Fa icon={darkMode ? faMoon : faSun} size="lg" /></span
>
</header>
<div
Expand Down

0 comments on commit 87b9366

Please sign in to comment.