import { FC, useState, useContext, ChangeEventHandler } from 'react'; import { Box, Button, Divider, IconButton, Popover, Typography, Avatar, styled, TypographyProps, MenuItem, TextField } from '@mui/material'; import PersonIcon from '@mui/icons-material/Person'; import AccountCircleIcon from '@mui/icons-material/AccountCircle'; import { AuthenticatedContext } from '../../contexts/authentication'; import { I18nContext } from '../../i18n/i18n-react'; import type { Locales } from '../../i18n/i18n-types'; import { locales } from '../..//i18n/i18n-util'; import { loadLocaleAsync } from '../../i18n/i18n-util.async'; const ItemTypography = styled(Typography)({ maxWidth: '250px', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }); const LayoutAuthMenu: FC = () => { const { me, signOut } = useContext(AuthenticatedContext); const [anchorEl, setAnchorEl] = useState(null); const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; const { locale, LL, setLocale } = useContext(I18nContext); const onLocaleSelected: ChangeEventHandler = async ({ target }) => { const loc = target.value as Locales; localStorage.setItem('lang', loc); await loadLocaleAsync(loc); setLocale(loc); }; const handleClose = () => { setAnchorEl(null); }; const open = Boolean(anchorEl); const id = anchorEl ? 'app-menu-popover' : undefined; return ( <> {locales.map((loc) => ( {loc} ))} {me.username} {me.admin ? LL.ADMIN() + ' ' + LL.USER() : LL.GUEST() + ' ' + LL.USER()} ); }; export default LayoutAuthMenu;