diff --git a/web/avatars/edit-user-avatar-menu.react.js b/web/avatars/edit-user-avatar-menu.react.js index 2c6cf9f22..5313022f0 100644 --- a/web/avatars/edit-user-avatar-menu.react.js +++ b/web/avatars/edit-user-avatar-menu.react.js @@ -1,105 +1,151 @@ // @flow import invariant from 'invariant'; import * as React from 'react'; import { EditUserAvatarContext } from 'lib/components/edit-user-avatar-provider.react.js'; import { useModalContext } from 'lib/components/modal-provider.react.js'; import SWMansionIcon from 'lib/components/SWMansionIcon.react.js'; +import { useENSAvatar } from 'lib/hooks/ens-cache.js'; +import { getETHAddressForUserInfo } from 'lib/shared/account-utils.js'; import css from './edit-user-avatar-menu.css'; import EmojiAvatarSelectionModal from './emoji-avatar-selection-modal.react.js'; +import CommIcon from '../CommIcon.react.js'; import MenuItem from '../components/menu-item.react.js'; import Menu from '../components/menu.react.js'; import { allowedMimeTypeString } from '../media/file-utils.js'; +import { useSelector } from '../redux/redux-utils.js'; const editIcon = (
); function EditUserAvatarMenu(): React.Node { + const currentUserInfo = useSelector(state => state.currentUserInfo); + const ethAddress: ?string = React.useMemo( + () => getETHAddressForUserInfo(currentUserInfo), + [currentUserInfo], + ); + const ensAvatarURI: ?string = useENSAvatar(ethAddress); + const editUserAvatarContext = React.useContext(EditUserAvatarContext); invariant(editUserAvatarContext, 'editUserAvatarContext should be set'); const { baseSetUserAvatar } = editUserAvatarContext; const removeUserAvatar = React.useCallback( () => baseSetUserAvatar({ type: 'remove' }), [baseSetUserAvatar], ); const { pushModal } = useModalContext(); const openEmojiSelectionModal = React.useCallback( () => pushModal(), [pushModal], ); const emojiMenuItem = React.useMemo( () => ( ), [openEmojiSelectionModal], ); const imageInputRef = React.useRef(); const onImageMenuItemClicked = React.useCallback( () => imageInputRef.current?.click(), [], ); const onImageSelected = React.useCallback( event => console.log(event.target.files), [], ); const imageMenuItem = React.useMemo( () => ( ), [onImageMenuItemClicked], ); + const setENSUserAvatar = React.useCallback( + () => baseSetUserAvatar({ type: 'ens' }), + [baseSetUserAvatar], + ); + + const ethereumIcon = React.useMemo( + () => , + [], + ); + + const ensMenuItem = React.useMemo( + () => ( + + ), + [ethereumIcon, setENSUserAvatar], + ); + const removeMenuItem = React.useMemo( () => ( ), [removeUserAvatar], ); - const menuItems = React.useMemo( - () => [emojiMenuItem, imageMenuItem, removeMenuItem], - [emojiMenuItem, imageMenuItem, removeMenuItem], - ); + const menuItems = React.useMemo(() => { + const items = [emojiMenuItem, imageMenuItem]; + if (ensAvatarURI) { + items.push(ensMenuItem); + } + if (currentUserInfo?.avatar) { + items.push(removeMenuItem); + } + return items; + }, [ + currentUserInfo?.avatar, + emojiMenuItem, + ensAvatarURI, + ensMenuItem, + imageMenuItem, + removeMenuItem, + ]); return (
{menuItems}
); } export default EditUserAvatarMenu; diff --git a/web/components/menu.css b/web/components/menu.css index 754a08ecd..453ec1417 100644 --- a/web/components/menu.css +++ b/web/components/menu.css @@ -1,95 +1,96 @@ button.menuButton { background-color: transparent; border: none; cursor: pointer; color: inherit; } div.menuActionList { position: absolute; z-index: 4; display: flex; flex-direction: column; background-color: var(--menu-bg); color: var(--menu-color); stroke: var(--menu-color); border-radius: 4px; padding: 4px 0; line-height: var(--line-height-text); min-width: max-content; } div.menuActionListThreadActions { font-size: var(--m-font-16); top: 40px; right: -20px; } div.menuActionListMemberActions { font-size: var(--xs-font-12); background-color: var(--menu-bg-light); color: var(--menu-color-light); stroke: var(--menu-color-light); top: 0; right: 5px; } div.menuActionListCommunityActions { font-size: var(--m-font-16); background-color: var(--menu-bg-light); color: var(--menu-color); stroke: var(--menu-color); top: 24px; } div.menuActionListRoleActions { font-size: var(--s-font-14); background-color: var(--menu-bg-light); color: var(--menu-color); stroke: var(--menu-color); margin-top: 20px; } button.menuAction { color: inherit; z-index: 1; padding: 12px 16px; line-height: 1.5; font-size: inherit; justify-content: start; } button.menuAction:hover { color: var(--menu-color-hover); stroke: var(--menu-color-hover); } div.menuActionIcon { display: flex; justify-content: center; + align-items: center; margin-right: 8px; height: 24px; width: 24px; } div.menuActionListMemberActions div.menuActionIcon { height: 18px; width: 18px; } button.menuActionDangerous { color: var(--menu-color-dangerous); stroke: var(--menu-color-dangerous); } button.menuActionDangerous:hover { color: var(--menu-color-dangerous-hover); stroke: var(--menu-color-dangerous-hover); } hr.separator { height: 1px; background: var(--menu-separator-color); margin: 10px 16px; max-width: 130px; border: none; }