Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024-09-12 fixes #107

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions frontend/public/images/icons/dark-mode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions frontend/public/images/icons/light-mode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 44 additions & 4 deletions frontend/src/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,56 @@
import { useEffect, useState } from "react";
import { useLocation } from "react-router-dom";

import { Menu } from "./Menu";

export const Layout = ({ children }: { children: React.ReactNode }) => {
const { pathname } = useLocation();
const [isDark, setIsDark] = useState(false);

useEffect(() => {
// set the initial state of the theme based on the user's preference
if (
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches &&
localStorage.getItem("theme") !== "light"
) {
setIsDark(true);
}

const handleColorSchemeChange = (event: MediaQueryListEvent) => {
// if there is a theme set in local storage, don't change the theme
if (
localStorage.getItem("theme") === "light" ||
localStorage.getItem("theme") === "dark"
)
return;

// else set the theme based on the event change
if (event.matches) {
setIsDark(true);
} else {
setIsDark(false);
}
};

window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", handleColorSchemeChange);

// Clean up the event listener
return () => {
window
.matchMedia("(prefers-color-scheme: dark)")
.removeEventListener("change", handleColorSchemeChange);
};
}, []);

return (
<>
<Menu />
<div className={isDark ? "dark" : ""}>
<Menu isDark={isDark} onDarkChange={(dark) => setIsDark(dark)} />

<div
className={`lg:pl-60 dark:bg-gray-950 dark:text-gray-100 ${pathname === "/map" ? "h-screen" : ""} sm:pt-14 md:pt-14 lg:pt-0`}
className={`lg:pl-60 dark:bg-gray-950 dark:text-gray-100 ${pathname === "/map" ? "h-screen" : ""} pt-14 lg:pt-0`}
>
<main className={`${pathname === "/map" ? "h-screen" : "py-1 "}`}>
<div
Expand All @@ -20,6 +60,6 @@ export const Layout = ({ children }: { children: React.ReactNode }) => {
</div>
</main>
</div>
</>
</div>
);
};
Loading