From d5c0493e35e3cd064b79cdb660b810e3aed3c0ae Mon Sep 17 00:00:00 2001 From: grimsi <9295182+grimsi@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:56:06 +0100 Subject: [PATCH] Added header navbar --- frontend/components/ProfileMenu.tsx | 82 +++++++++++++++++++++++++++++ frontend/views/MainLayout.tsx | 60 ++++++++++----------- package.json | 4 +- src/main/resources/application.yml | 1 - 4 files changed, 112 insertions(+), 35 deletions(-) create mode 100644 frontend/components/ProfileMenu.tsx diff --git a/frontend/components/ProfileMenu.tsx b/frontend/components/ProfileMenu.tsx new file mode 100644 index 0000000..37542d0 --- /dev/null +++ b/frontend/components/ProfileMenu.tsx @@ -0,0 +1,82 @@ +import {useState} from "react"; +import {Button, Menu, MenuHandler, MenuItem, MenuList} from "@material-tailwind/react"; +import { + faChevronDown, + faChevronUp, + faCog, + faQuestionCircle, + faSignOut, + faUser +} from "@fortawesome/free-solid-svg-icons"; +import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; +import {useAuth} from "Frontend/util/auth"; +import {Avatar} from "@hilla/react-components/Avatar"; +import {useNavigate} from "react-router-dom"; + +export default function ProfileMenu() { + const [isMenuOpen, setIsMenuOpen] = useState(false); + const {state, logout} = useAuth(); + const navigate = useNavigate(); + + const profileMenuItems = [ + { + label: "My Profile", + icon: faUser, + onClick: () => alert("Profile") + }, + { + label: "Administration", + icon: faCog, + onClick: () => alert("Administration"), + showIf: state.user?.authorities?.some(a => a?.includes("ADMIN")) + }, + { + label: "Help", + icon: faQuestionCircle, + onClick: () => window.open("https://github.com/gameyfin/gameyfin/tree/v2", "_blank") + }, + { + label: "Sign Out", + icon: faSignOut, + onClick: () => logout(), + color: "red-500" + }, + ]; + + return ( + + + + + + {profileMenuItems.map(({label, icon, onClick, showIf, color}) => { + return ( + (showIf === undefined || showIf === true) ? + + +

{label}

+
: null + ); + })} +
+
+ ); +} \ No newline at end of file diff --git a/frontend/views/MainLayout.tsx b/frontend/views/MainLayout.tsx index 00315bf..8a9c710 100644 --- a/frontend/views/MainLayout.tsx +++ b/frontend/views/MainLayout.tsx @@ -1,11 +1,9 @@ -import {AppLayout} from '@hilla/react-components/AppLayout.js'; -import {Avatar} from '@hilla/react-components/Avatar.js'; -import {Button} from '@hilla/react-components/Button.js'; -import {DrawerToggle} from '@hilla/react-components/DrawerToggle.js'; import {useAuth} from 'Frontend/util/auth.js'; import {useRouteMetadata} from 'Frontend/util/routing.js'; import {useEffect} from 'react'; -import {Outlet} from 'react-router-dom'; +import {Navbar} from "@material-tailwind/react"; +import ProfileMenu from "Frontend/components/ProfileMenu"; +import {Outlet} from "react-router-dom"; const navLinkClasses = ({isActive}: any) => { return `block rounded-m p-s ${isActive ? 'bg-primary-10 text-primary' : 'text-body'}`; @@ -18,35 +16,33 @@ export default function MainLayout() { }, [currentTitle]); const {state, logout} = useAuth(); - return ( - -
-
-

My App

- -
-
- {state.user ? ( - <> -
- - {state.user.name} -
- - - ) : ( - Sign in - )} -
-
- -

- {currentTitle} -

+ return ( + <> + +
+ Gameyfin + +
+
-
+ ); } + +/**/ diff --git a/package.json b/package.json index 0e25da1..e43888c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "no-name", - "license": "UNLICENSED", + "name": "Gameyfin", + "version": "2.0.0-ALPHA", "type": "module", "dependencies": { "@fortawesome/fontawesome-svg-core": "^6.5.1", diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 15429c9..7bd9411 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -19,7 +19,6 @@ spring: name: Gameyfin vaadin: - launch-browser: true # To improve the performance during development. # For more information https://vaadin.com/docs/flow/spring/tutorial-spring-configuration.html#special-configuration-parameters whitelisted-packages: