From 7daac080f52ab4133a3899ad8de89aab055fd3a7 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 10 May 2022 22:24:20 +0200 Subject: [PATCH] feat: improve navigation slightly --- frontend/src/lib/NavItem.tsx | 22 ++++++ frontend/src/lib/Navigation.tsx | 114 ++++++++++++++++---------------- 2 files changed, 79 insertions(+), 57 deletions(-) create mode 100644 frontend/src/lib/NavItem.tsx diff --git a/frontend/src/lib/NavItem.tsx b/frontend/src/lib/NavItem.tsx new file mode 100644 index 0000000..38e3db7 --- /dev/null +++ b/frontend/src/lib/NavItem.tsx @@ -0,0 +1,22 @@ +import { ReactNode, PropsWithChildren } from "react"; +import { Link } from "react-router-dom"; + +export interface Props { + children?: ReactNode | undefined; + to: string; + plain?: boolean | undefined; // Do not wrap in
  • +} + +export default function NavItem(props: Props) { + const ret = + {props.children} + + + if (props.plain) { + return ret + } + return
  • {ret}
  • ; +} diff --git a/frontend/src/lib/Navigation.tsx b/frontend/src/lib/Navigation.tsx index d4a4314..889e3ec 100644 --- a/frontend/src/lib/Navigation.tsx +++ b/frontend/src/lib/Navigation.tsx @@ -1,13 +1,15 @@ -import Logo from "./logo"; import { useState } from "react"; import { Link } from "react-router-dom"; import { MoonStars, Sun, List } from "react-bootstrap-icons"; +import NavItem from "./NavItem"; +import Logo from "./logo"; + function Navigation() { const [darkTheme, setDarkTheme] = useState( localStorage.theme === "dark" || - (!("theme" in localStorage) && - window.matchMedia("(prefers-color-scheme: dark)").matches) + (!("theme" in localStorage) && + window.matchMedia("(prefers-color-scheme: dark)").matches) ); const [showMenu, setShowMenu] = useState(false); @@ -18,73 +20,71 @@ function Navigation() { document.documentElement.classList.remove("dark"); } - const storeTheme = (system: boolean) => { - if (system) { + const storeTheme = (useDarkTheme: boolean | null) => { + if (useDarkTheme === null) { localStorage.removeItem("theme"); } else { - localStorage.setItem("theme", darkTheme ? "dark" : "light"); + localStorage.setItem("theme", useDarkTheme ? "dark" : "light"); } }; return ( -
    -
    -
    -
    - - - -
    - -
    -
    { - storeTheme(false); - setDarkTheme(!darkTheme); - }} - title={ - darkTheme ? "Switch to light mode" : "Switch to dark mode" - } - className="cursor-pointer" - > - {darkTheme ? ( - - ) : ( - - )} -
    -
    setShowMenu(!showMenu)} title="Show menu" className="cursor-pointer flex lg:hidden"> + <> +
    +
    +
    +
    + + + +
    + +
    +
    { + setDarkTheme(!darkTheme); + storeTheme(!darkTheme); + }} + title={ + darkTheme ? "Switch to light mode" : "Switch to dark mode" + } + className="cursor-pointer" + > + {darkTheme ? ( + + ) : ( + + )} +
    +
    setShowMenu(!showMenu)} title="Show menu" className="cursor-pointer flex lg:hidden"> +
    -
    -
    + + ); }