// @flow import 'scss/component/_header.scss'; // $FlowFixMe import { Global } from '@emotion/react'; import { Menu as MuiMenu, MenuItem as MuiMenuItem } from '@mui/material'; import * as ICONS from 'constants/icons'; import * as PAGES from 'constants/pages'; import ChannelThumbnail from 'component/channelThumbnail'; import classnames from 'classnames'; import HeaderMenuLink from 'component/common/header-menu-link'; import Icon from 'component/common/icon'; import React from 'react'; import Skeleton from '@mui/material/Skeleton'; import ChannelSelector from 'component/channelSelector'; import Button from 'component/button'; import ClickAwayListener from '@mui/material/ClickAwayListener'; type HeaderMenuButtonProps = { myChannelClaimIds: ?Array, activeChannelClaim: ?ChannelClaim, authenticated: boolean, email: ?string, signOut: () => void, }; export default function HeaderProfileMenuButton(props: HeaderMenuButtonProps) { const { myChannelClaimIds, activeChannelClaim, authenticated, email, signOut } = props; const [anchorEl, setAnchorEl] = React.useState(null); const [clicked, setClicked] = React.useState(false); const open = Boolean(anchorEl); const handleClick = (event) => setAnchorEl(!anchorEl ? event.currentTarget : null); const handleClose = () => setAnchorEl(null); const activeChannelUrl = activeChannelClaim && activeChannelClaim.permanent_url; // activeChannel will be: undefined = fetching, null = nothing, or { channel claim } const noActiveChannel = activeChannelUrl === null; const pendingChannelFetch = !noActiveChannel && myChannelClaimIds === undefined; const handleClickAway = () => { if (!clicked) { if (open) setClicked(true); } else { setAnchorEl(null); setClicked(false); } }; React.useEffect(() => { if (!open) setClicked(false); }, [open]); const menuProps = { id: 'basic-menu', anchorEl, open, onClose: handleClose, MenuListProps: { 'aria-labelledby': 'basic-button', sx: { padding: 'var(--spacing-xs)' }, }, className: 'menu__list--header', sx: { 'z-index': 2 }, PaperProps: { className: 'MuiMenu-list--paper' }, disableScrollLock: true, }; return ( <> {open && ( )}
{pendingChannelFetch ? ( ) : ( )} {authenticated ? (



{__('Sign Out')}
{email}
) : ( )}
); }