2021-12-20 13:29:51 +01:00
|
|
|
// @flow
|
2021-12-21 13:42:28 +01:00
|
|
|
import 'scss/component/_header.scss';
|
|
|
|
|
2022-05-05 12:31:56 +02:00
|
|
|
// $FlowFixMe
|
|
|
|
import { Global } from '@emotion/react';
|
|
|
|
|
2022-05-04 14:34:31 +02:00
|
|
|
import { Menu as MuiMenu, MenuItem as MuiMenuItem } from '@mui/material';
|
2021-12-20 13:29:51 +01:00
|
|
|
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';
|
2021-12-21 14:21:14 +01:00
|
|
|
import Skeleton from '@mui/material/Skeleton';
|
2022-05-04 14:34:31 +02:00
|
|
|
import ChannelSelector from 'component/channelSelector';
|
|
|
|
import Button from 'component/button';
|
2022-06-09 16:29:56 +02:00
|
|
|
import ClickAwayListener from '@mui/material/ClickAwayListener';
|
2021-12-20 13:29:51 +01:00
|
|
|
|
|
|
|
type HeaderMenuButtonProps = {
|
2022-02-18 14:14:54 +01:00
|
|
|
myChannelClaimIds: ?Array<string>,
|
2022-05-09 13:05:29 +02:00
|
|
|
activeChannelClaim: ?ChannelClaim,
|
2022-01-06 03:56:17 +01:00
|
|
|
authenticated: boolean,
|
2021-12-20 13:29:51 +01:00
|
|
|
email: ?string,
|
|
|
|
signOut: () => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function HeaderProfileMenuButton(props: HeaderMenuButtonProps) {
|
2022-05-09 13:05:29 +02:00
|
|
|
const { myChannelClaimIds, activeChannelClaim, authenticated, email, signOut } = props;
|
2022-02-18 18:22:21 +01:00
|
|
|
|
2022-05-04 14:34:31 +02:00
|
|
|
const [anchorEl, setAnchorEl] = React.useState(null);
|
2022-06-09 16:29:56 +02:00
|
|
|
const [clicked, setClicked] = React.useState(false);
|
2022-05-04 14:34:31 +02:00
|
|
|
const open = Boolean(anchorEl);
|
2022-05-05 12:31:56 +02:00
|
|
|
const handleClick = (event) => setAnchorEl(!anchorEl ? event.currentTarget : null);
|
|
|
|
const handleClose = () => setAnchorEl(null);
|
2022-05-04 14:34:31 +02:00
|
|
|
|
2022-05-09 13:05:29 +02:00
|
|
|
const activeChannelUrl = activeChannelClaim && activeChannelClaim.permanent_url;
|
2022-02-18 18:22:21 +01:00
|
|
|
// activeChannel will be: undefined = fetching, null = nothing, or { channel claim }
|
|
|
|
const noActiveChannel = activeChannelUrl === null;
|
|
|
|
const pendingChannelFetch = !noActiveChannel && myChannelClaimIds === undefined;
|
2021-12-20 13:29:51 +01:00
|
|
|
|
2022-06-09 16:29:56 +02:00
|
|
|
const handleClickAway = () => {
|
|
|
|
if (!clicked) {
|
|
|
|
if (open) setClicked(true);
|
|
|
|
} else {
|
|
|
|
setAnchorEl(null);
|
|
|
|
setClicked(false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (!open) setClicked(false);
|
|
|
|
}, [open]);
|
|
|
|
|
2022-05-05 12:31:56 +02:00
|
|
|
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' },
|
2022-06-09 16:29:56 +02:00
|
|
|
disableScrollLock: true,
|
2022-05-05 12:31:56 +02:00
|
|
|
};
|
|
|
|
|
2021-12-20 13:29:51 +01:00
|
|
|
return (
|
2022-05-05 12:31:56 +02:00
|
|
|
<>
|
|
|
|
{open && (
|
|
|
|
<Global
|
|
|
|
styles={{
|
|
|
|
body: {
|
2022-05-12 17:16:12 +02:00
|
|
|
overflowY: 'scroll !important',
|
|
|
|
paddingRight: '0px !important',
|
2022-05-05 12:31:56 +02:00
|
|
|
},
|
2022-05-04 16:45:34 +02:00
|
|
|
}}
|
2022-05-05 12:31:56 +02:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<div className="header__buttons">
|
|
|
|
{pendingChannelFetch ? (
|
|
|
|
<Skeleton variant="circular" animation="wave" className="header__navigationItem--iconSkeleton" />
|
|
|
|
) : (
|
|
|
|
<Button
|
|
|
|
id="basic-button"
|
|
|
|
aria-controls={open ? 'basic-menu' : undefined}
|
|
|
|
aria-haspopup="true"
|
|
|
|
aria-expanded={open ? 'true' : undefined}
|
|
|
|
onClick={handleClick}
|
|
|
|
className={classnames('header__navigationItem', {
|
|
|
|
'header__navigationItem--icon': !activeChannelUrl,
|
|
|
|
'header__navigationItem--profilePic': activeChannelUrl,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{activeChannelUrl ? (
|
|
|
|
<ChannelThumbnail uri={activeChannelUrl} hideTooltip small noLazyLoad showMemberBadge />
|
|
|
|
) : (
|
|
|
|
<Icon size={18} icon={ICONS.ACCOUNT} aria-hidden />
|
|
|
|
)}
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
{authenticated ? (
|
2022-06-09 16:29:56 +02:00
|
|
|
<ClickAwayListener onClickAway={handleClickAway}>
|
|
|
|
<MuiMenu {...menuProps}>
|
|
|
|
<ChannelSelector storeSelection isHeaderMenu />
|
2022-06-03 15:43:31 +02:00
|
|
|
|
2022-06-09 16:29:56 +02:00
|
|
|
<hr className="menu__separator" />
|
|
|
|
<HeaderMenuLink useMui page={PAGES.UPLOADS} icon={ICONS.PUBLISH} name={__('Uploads')} />
|
|
|
|
<HeaderMenuLink useMui page={PAGES.CHANNELS} icon={ICONS.CHANNEL} name={__('Channels')} />
|
|
|
|
<HeaderMenuLink
|
|
|
|
useMui
|
|
|
|
page={PAGES.CREATOR_DASHBOARD}
|
|
|
|
icon={ICONS.ANALYTICS}
|
|
|
|
name={__('Creator Analytics')}
|
|
|
|
/>
|
2022-06-03 15:43:31 +02:00
|
|
|
|
2022-06-09 16:29:56 +02:00
|
|
|
<hr className="menu__separator" />
|
|
|
|
<HeaderMenuLink useMui page={PAGES.REWARDS} icon={ICONS.REWARDS} name={__('Rewards')} />
|
|
|
|
<HeaderMenuLink useMui page={PAGES.INVITE} icon={ICONS.INVITE} name={__('Invites')} />
|
|
|
|
<HeaderMenuLink useMui page={PAGES.ODYSEE_MEMBERSHIP} icon={ICONS.UPGRADE} name={__('Odysee Premium')} />
|
2021-12-20 13:29:51 +01:00
|
|
|
|
2022-06-09 16:29:56 +02:00
|
|
|
<hr className="menu__separator" />
|
|
|
|
<HeaderMenuLink useMui page={PAGES.SETTINGS} icon={ICONS.SETTINGS} name={__('Settings')} />
|
|
|
|
<HeaderMenuLink useMui page={PAGES.HELP} icon={ICONS.HELP} name={__('Help')} />
|
2022-06-03 15:43:31 +02:00
|
|
|
|
2022-06-09 16:29:56 +02:00
|
|
|
<hr className="menu__separator" />
|
|
|
|
<MuiMenuItem onClick={signOut}>
|
|
|
|
<div className="menu__link" style={{ flexDirection: 'column', alignItems: 'flex-start' }}>
|
|
|
|
<div className="menu__link-label">
|
|
|
|
<Icon aria-hidden icon={ICONS.SIGN_OUT} />
|
|
|
|
{__('Sign Out')}
|
|
|
|
</div>
|
|
|
|
<span className="menu__link-help">{email}</span>
|
2022-05-05 12:31:56 +02:00
|
|
|
</div>
|
2022-06-09 16:29:56 +02:00
|
|
|
</MuiMenuItem>
|
|
|
|
</MuiMenu>
|
|
|
|
</ClickAwayListener>
|
2022-05-05 12:31:56 +02:00
|
|
|
) : (
|
2022-06-09 16:29:56 +02:00
|
|
|
<ClickAwayListener onClickAway={handleClickAway}>
|
|
|
|
<MuiMenu {...menuProps}>
|
|
|
|
<HeaderMenuLink useMui page={PAGES.AUTH_SIGNIN} icon={ICONS.SIGN_IN} name={__('Log In')} />
|
|
|
|
<HeaderMenuLink useMui page={PAGES.AUTH} icon={ICONS.SIGN_UP} name={__('Sign Up')} />
|
|
|
|
<HeaderMenuLink useMui page={PAGES.SETTINGS} icon={ICONS.SETTINGS} name={__('Settings')} />
|
|
|
|
<HeaderMenuLink useMui page={PAGES.HELP} icon={ICONS.HELP} name={__('Help')} />
|
|
|
|
</MuiMenu>
|
|
|
|
</ClickAwayListener>
|
2022-05-05 12:31:56 +02:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
2021-12-20 13:29:51 +01:00
|
|
|
);
|
|
|
|
}
|