Commit dddbabdf authored by Max Alekseenko's avatar Max Alekseenko

change profile button

parent 39fb8bbc
<svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M10 1.593A8.407 8.407 0 0 0 3.332 15.12c1.465-2.162 3.89-3.556 6.668-3.556 2.784 0 5.2 1.461 6.66 3.567A8.407 8.407 0 0 0 10 1.593ZM0 10C0 4.477 4.477 0 10 0s10 4.477 10 10-4.477 10-10 10S0 15.523 0 10Zm4.476 6.287c1.443 1.295 3.412 2.039 5.524 2.039a8.529 8.529 0 0 0 5.51-2.045c-1.17-1.85-3.2-3.123-5.51-3.123-2.333 0-4.363 1.225-5.524 3.129Zm3.388-8.975a2.136 2.136 0 1 1 4.272 0 2.136 2.136 0 0 1-4.272 0ZM10 3.584a3.729 3.729 0 1 0 0 7.457 3.729 3.729 0 0 0 0-7.457Z" fill="currentColor"/>
</svg>
...@@ -22,7 +22,7 @@ const Home = () => { ...@@ -22,7 +22,7 @@ const Home = () => {
minW={{ base: 'unset', lg: '900px' }} minW={{ base: 'unset', lg: '900px' }}
data-label="hero plate" data-label="hero plate"
> >
<Flex mb={{ base: 6, lg: 8 }} justifyContent="space-between"> <Flex mb={{ base: 6, lg: 8 }} justifyContent="space-between" alignItems="center">
<Heading <Heading
as="h1" as="h1"
size={{ base: 'md', lg: 'xl' }} size={{ base: 'md', lg: 'xl' }}
...@@ -33,7 +33,7 @@ const Home = () => { ...@@ -33,7 +33,7 @@ const Home = () => {
Welcome to { config.chain.name } explorer Welcome to { config.chain.name } explorer
</Heading> </Heading>
<Box display={{ base: 'none', lg: 'block' }}> <Box display={{ base: 'none', lg: 'block' }}>
{ config.features.account.isEnabled && <ProfileMenuDesktop/> } { config.features.account.isEnabled && <ProfileMenuDesktop isHomePage/> }
</Box> </Box>
</Flex> </Flex>
<LightMode> <LightMode>
......
import { SkeletonCircle, Image } from '@chakra-ui/react'; import { SkeletonCircle, Image, Icon } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import profileIcon from 'icons/profile.svg';
import { useAppContext } from 'lib/contexts/app'; import { useAppContext } from 'lib/contexts/app';
import * as cookies from 'lib/cookies'; import * as cookies from 'lib/cookies';
import useFetchProfileInfo from 'lib/hooks/useFetchProfileInfo'; import useFetchProfileInfo from 'lib/hooks/useFetchProfileInfo';
import IdenticonGithub from 'ui/shared/IdenticonGithub';
interface Props { interface Props {
size: number; size: number;
...@@ -34,7 +34,7 @@ const UserAvatar = ({ size }: Props) => { ...@@ -34,7 +34,7 @@ const UserAvatar = ({ size }: Props) => {
boxSize={ `${ size }px` } boxSize={ `${ size }px` }
borderRadius="full" borderRadius="full"
overflow="hidden" overflow="hidden"
fallback={ isImageLoadError || !data?.avatar ? <IdenticonGithub size={ size } seed={ data?.email || 'randomness' } flexShrink={ 0 }/> : undefined } fallback={ isImageLoadError || !data?.avatar ? <Icon as={ profileIcon } boxSize={ 5 }/> : undefined }
onError={ handleImageLoadError } onError={ handleImageLoadError }
/> />
); );
......
import type { ButtonProps } from '@chakra-ui/react'; import type { IconButtonProps } from '@chakra-ui/react';
import { Popover, PopoverContent, PopoverBody, PopoverTrigger, Button } from '@chakra-ui/react'; import { Popover, PopoverContent, PopoverBody, PopoverTrigger, IconButton, useColorModeValue } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import useFetchProfileInfo from 'lib/hooks/useFetchProfileInfo'; import useFetchProfileInfo from 'lib/hooks/useFetchProfileInfo';
...@@ -8,7 +8,11 @@ import * as mixpanel from 'lib/mixpanel/index'; ...@@ -8,7 +8,11 @@ import * as mixpanel from 'lib/mixpanel/index';
import UserAvatar from 'ui/shared/UserAvatar'; import UserAvatar from 'ui/shared/UserAvatar';
import ProfileMenuContent from 'ui/snippets/profileMenu/ProfileMenuContent'; import ProfileMenuContent from 'ui/snippets/profileMenu/ProfileMenuContent';
const ProfileMenuDesktop = () => { type Props = {
isHomePage?: boolean;
};
const ProfileMenuDesktop = ({ isHomePage }: Props) => {
const { data, error, isLoading } = useFetchProfileInfo(); const { data, error, isLoading } = useFetchProfileInfo();
const loginUrl = useLoginUrl(); const loginUrl = useLoginUrl();
const [ hasMenu, setHasMenu ] = React.useState(false); const [ hasMenu, setHasMenu ] = React.useState(false);
...@@ -27,7 +31,7 @@ const ProfileMenuDesktop = () => { ...@@ -27,7 +31,7 @@ const ProfileMenuDesktop = () => {
); );
}, []); }, []);
const buttonProps: Partial<ButtonProps> = (() => { const iconButtonProps: Partial<IconButtonProps> = (() => {
if (hasMenu || !loginUrl) { if (hasMenu || !loginUrl) {
return {}; return {};
} }
...@@ -39,18 +43,45 @@ const ProfileMenuDesktop = () => { ...@@ -39,18 +43,45 @@ const ProfileMenuDesktop = () => {
}; };
})(); })();
const variant = React.useMemo(() => {
if (data?.avatar) {
return 'subtle';
}
return isHomePage ? 'solid' : 'outline';
}, [ data?.avatar, isHomePage ]);
let iconButtonStyles: Partial<IconButtonProps> = {};
const themedBackground = useColorModeValue('blackAlpha.50', 'whiteAlpha.50');
const themedBorderColor = useColorModeValue('gray.300', 'gray.700');
const themedColor = useColorModeValue('blackAlpha.800', 'gray.400');
if (data?.avatar) {
iconButtonStyles = {
bg: isHomePage ? '#EBF8FF' : themedBackground,
};
} else if (isHomePage) {
iconButtonStyles = {
color: '#fff',
};
} else {
iconButtonStyles = {
borderColor: themedBorderColor,
color: themedColor,
};
}
return ( return (
<Popover openDelay={ 300 } placement="bottom-end" gutter={ 10 } isLazy> <Popover openDelay={ 300 } placement="bottom-end" gutter={ 10 } isLazy>
<PopoverTrigger> <PopoverTrigger>
<Button <IconButton
variant="unstyled" aria-label="profile menu"
display="block" icon={ <UserAvatar size={ 20 }/> }
boxSize="50px" variant={ variant }
colorScheme="blue"
boxSize="40px"
flexShrink={ 0 } flexShrink={ 0 }
{ ...buttonProps } { ...iconButtonProps }
> { ...iconButtonStyles }
<UserAvatar size={ 50 }/> />
</Button>
</PopoverTrigger> </PopoverTrigger>
{ hasMenu && ( { hasMenu && (
<PopoverContent w="212px"> <PopoverContent w="212px">
......
import { Box, Drawer, DrawerOverlay, DrawerContent, DrawerBody, useDisclosure, Button } from '@chakra-ui/react'; import { Drawer, DrawerOverlay, DrawerContent, DrawerBody, useDisclosure, IconButton, useColorModeValue } from '@chakra-ui/react';
import type { ButtonProps } from '@chakra-ui/react'; import type { IconButtonProps } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import useFetchProfileInfo from 'lib/hooks/useFetchProfileInfo'; import useFetchProfileInfo from 'lib/hooks/useFetchProfileInfo';
...@@ -29,7 +29,7 @@ const ProfileMenuMobile = () => { ...@@ -29,7 +29,7 @@ const ProfileMenuMobile = () => {
} }
}, [ data, error?.status, isLoading ]); }, [ data, error?.status, isLoading ]);
const buttonProps: Partial<ButtonProps> = (() => { const iconButtonProps: Partial<IconButtonProps> = (() => {
if (hasMenu || !loginUrl) { if (hasMenu || !loginUrl) {
return {}; return {};
} }
...@@ -41,19 +41,25 @@ const ProfileMenuMobile = () => { ...@@ -41,19 +41,25 @@ const ProfileMenuMobile = () => {
}; };
})(); })();
const themedBackground = useColorModeValue('blackAlpha.50', 'whiteAlpha.50');
const themedBorderColor = useColorModeValue('gray.300', 'gray.700');
const themedColor = useColorModeValue('blackAlpha.800', 'gray.400');
return ( return (
<> <>
<Box padding={ 2 } onClick={ hasMenu ? onOpen : undefined }> <IconButton
<Button aria-label="profile menu"
variant="unstyled" icon={ <UserAvatar size={ 20 }/> }
display="block" variant={ data?.avatar ? 'subtle' : 'outline' }
boxSize="24px" colorScheme="gray"
flexShrink={ 0 } boxSize="40px"
{ ...buttonProps } flexShrink={ 0 }
> bg={ data?.avatar ? themedBackground : undefined }
<UserAvatar size={ 24 }/> color={ themedColor }
</Button> borderColor={ !data?.avatar ? themedBorderColor : undefined }
</Box> onClick={ hasMenu ? onOpen : undefined }
{ ...iconButtonProps }
/>
{ hasMenu && ( { hasMenu && (
<Drawer <Drawer
isOpen={ isOpen } isOpen={ isOpen }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment