diff --git a/pac-man-board-game/ClientApp/src/components/navMenu.tsx b/pac-man-board-game/ClientApp/src/components/navMenu.tsx index e453c99..607cce0 100644 --- a/pac-man-board-game/ClientApp/src/components/navMenu.tsx +++ b/pac-man-board-game/ClientApp/src/components/navMenu.tsx @@ -1,32 +1,27 @@ import React, {FC} from "react"; import {Link, useNavigate} from "react-router-dom"; -import {useAtom} from "jotai"; +import {useAtom, useAtomValue} from "jotai"; import {thisPlayerAtom} from "../utils/state"; +import {UserCircleIcon} from "@heroicons/react/24/outline"; +import useToggle from "../hooks/useToggle"; const NavMenu: FC = () => { - const [player, setPlayer] = useAtom(thisPlayerAtom); - const navigate = useNavigate(); - - async function logout(): Promise { - setPlayer(undefined); - navigate("/login"); - } + const player = useAtomValue(thisPlayerAtom); return ( -
+
@@ -41,3 +36,31 @@ const NavItem: FC = ({to, children, className}) => ( {children} ) + +const ProfileDropdown: FC = ({className}) => { + const [player, setPlayer] = useAtom(thisPlayerAtom); + const [isOpened, toggle] = useToggle(false); + const navigate = useNavigate(); + + async function logout(): Promise { + setPlayer(undefined); + navigate("/login"); + } + + return ( + <> +
  • toggle()}> + + {player?.username} +
  • + { + isOpened && +
    + +
    + } + + ) +} diff --git a/pac-man-board-game/ClientApp/src/hooks/useToggle.ts b/pac-man-board-game/ClientApp/src/hooks/useToggle.ts new file mode 100644 index 0000000..b41d4c9 --- /dev/null +++ b/pac-man-board-game/ClientApp/src/hooks/useToggle.ts @@ -0,0 +1,7 @@ +import {useState} from "react"; + +export default function useToggle(defaultValue = false): [boolean, (value?: boolean) => void] { + const [value, setValue] = useState(defaultValue); + const toggleValue = (newValue?: boolean) => newValue ? setValue(newValue) : setValue(!value); + return [value, toggleValue]; +} \ No newline at end of file