diff --git a/torchci/components/benchmark_v3/pages/BenchmarkListPage.tsx b/torchci/components/benchmark_v3/pages/BenchmarkListPage.tsx index 83a07e5752..7b7fcb7c4e 100644 --- a/torchci/components/benchmark_v3/pages/BenchmarkListPage.tsx +++ b/torchci/components/benchmark_v3/pages/BenchmarkListPage.tsx @@ -23,22 +23,26 @@ export function getBenchmarkMainRouteById(id: string): string | undefined { export function benchmarkCategoryCardToNavGroup( categories: BenchmarkCategoryGroup[] ): (NavCategory | NavItem | NavDivider)[] { - const items: (NavCategory | NavItem)[] = categories + const items = categories .map((c: BenchmarkCategoryGroup) => { if (c.items.length === 1) { - const item: NavItem = { + const item = { label: c.items[0].name, route: c.items[0].route, - type: "item", + type: "item" as const, }; return item; } - const group: NavCategory = { + const group = { label: c.title, items: c.items .sort((a, b) => a.name.localeCompare(b.name)) - .map((i) => ({ label: i.name, route: i.route, type: "item" })), - type: "group", + .map((i) => ({ + label: i.name, + route: i.route, + type: "item" as const, + })), + type: "group" as const, }; return group; }) @@ -53,10 +57,10 @@ export function benchmarkCategoryCardToNavGroup( return [ ...items, - { type: "divider" }, + { type: "divider" as const }, { label: "View All Benchmarks", - type: "item", + type: "item" as const, route: "/benchmark/benchmark_list", }, ]; diff --git a/torchci/components/layout/LoginSection.tsx b/torchci/components/layout/LoginSection.tsx index 8d914394c0..16487d9d36 100644 --- a/torchci/components/layout/LoginSection.tsx +++ b/torchci/components/layout/LoginSection.tsx @@ -1,10 +1,10 @@ import QuestionMarkIcon from "@mui/icons-material/QuestionMark"; import SyncIcon from "@mui/icons-material/Sync"; -import { Button as _Button, Menu, MenuItem } from "@mui/material"; +import { Button as _Button, Link } from "@mui/material"; +import { Box } from "@mui/system"; import { signIn, signOut, useSession } from "next-auth/react"; -import Link from "next/link"; -import React from "react"; import styles from "./LoginSection.module.css"; +import { NavBarGroupDropdown, NavItem } from "./NavBarGroupDropdown"; const Button = (props: any) => { // Make button as small as possible @@ -13,64 +13,78 @@ const Button = (props: any) => { export default function LoginSection() { const { data: session, status } = useSession(); - const [anchorEl, setAnchorEl] = React.useState(null); - const onClick = (event: any) => { - setAnchorEl(event.currentTarget); - }; - const onClose = () => { - setAnchorEl(null); - }; - return ( - <> - {status == "loading" && ( - // Shows up very briefly while api responds - - )} - {status != "loading" && !session?.user && ( - + + + ); + } + + // If not signed in, just show a sign in button (no dropdown) + if (!session?.user) { + return ( + { + e.preventDefault(); + signIn(); + }} + > + + + ); + } + + // If signed in, show dropdown with user info + const items: NavItem[] = [ + { + label: ( + e.preventDefault()} + > + Signed in as {session.user.name} + + ), + type: "item", + route: "#", + }, + { + type: "item", + route: "/api/auth/signout", + label: ( + { e.preventDefault(); - signIn(); + signOut(); + }} + style={{ + textDecoration: "none", + color: "inherit", + cursor: "pointer", }} > - - - )} - {session && ( - <> - - - {session.user?.name && ( - Signed in as {session.user.name} - )} - { - e.preventDefault(); - signOut(); - }} - > - Sign out - - - - )} - + Sign out + + ), + }, + ]; + + const title = session?.user?.image ? ( + + ) : ( + // Hopefully shouldn't get here + ); + + return ; } diff --git a/torchci/components/layout/NavBar.tsx b/torchci/components/layout/NavBar.tsx index 8d901cd125..33a6e7f12d 100644 --- a/torchci/components/layout/NavBar.tsx +++ b/torchci/components/layout/NavBar.tsx @@ -268,9 +268,7 @@ function NavBar() {
  • -
  • - -
  • + diff --git a/torchci/components/layout/NavBarGroupDropdown.tsx b/torchci/components/layout/NavBarGroupDropdown.tsx index ba25e53690..f22a549dbb 100644 --- a/torchci/components/layout/NavBarGroupDropdown.tsx +++ b/torchci/components/layout/NavBarGroupDropdown.tsx @@ -10,7 +10,11 @@ import { import { Box } from "@mui/system"; import { Fragment, useEffect, useMemo, useRef, useState } from "react"; -export type NavItem = { label: string; route: string; type: "item" }; +export type NavItem = { + label: string | JSX.Element; + route: string; + type: "item"; +}; export type NavCategory = { label: string; items: NavItem[]; type: "group" }; export type NavDivider = { type: "divider" }; @@ -23,9 +27,11 @@ export type NavDivider = { type: "divider" }; export function NavBarGroupDropdown({ title, items, + showCarrot = true, }: { - title: string; + title: string | JSX.Element; items: (NavCategory | NavItem | NavDivider)[]; + showCarrot?: boolean; }) { const [anchorEl, setAnchorEl] = useState(null); const open = Boolean(anchorEl); @@ -86,9 +92,11 @@ export function NavBarGroupDropdown({ fontFamily: "inherit", fontSize: "inherit", fontWeight: 400, + minWidth: 0, }} > - {title} ▾ + {title} + {showCarrot && " ▾"}