Commit a630b361 authored by Max Alekseenko's avatar Max Alekseenko

add tooltip

parent 9fc9d175
...@@ -177,6 +177,7 @@ const MarketplaceAppCard = ({ ...@@ -177,6 +177,7 @@ const MarketplaceAppCard = ({
rate={ rateApp } rate={ rateApp }
isSending={ isSendingRating } isSending={ isSendingRating }
isLoading={ isRatingLoading } isLoading={ isRatingLoading }
canRate={ Math.random() > 0.5 }
/> />
<IconButton <IconButton
aria-label="Mark as favorite" aria-label="Mark as favorite"
......
...@@ -172,6 +172,7 @@ const MarketplaceAppModal = ({ ...@@ -172,6 +172,7 @@ const MarketplaceAppModal = ({
isSending={ isSendingRating } isSending={ isSendingRating }
isLoading={ isRatingLoading } isLoading={ isRatingLoading }
fullView fullView
canRate={ Math.random() > 0.5 }
/> />
</Box> </Box>
......
...@@ -14,9 +14,13 @@ type Props = { ...@@ -14,9 +14,13 @@ type Props = {
isSending?: boolean; isSending?: boolean;
isLoading?: boolean; isLoading?: boolean;
fullView?: boolean; fullView?: boolean;
canRate: boolean;
}; };
const Rating = ({ appId, rating, recordId, isRatedByUser, rate, isSending, isLoading, fullView }: Props) => { const Rating = ({
appId, rating, recordId, isRatedByUser, rate,
isSending, isLoading, fullView, canRate,
}: Props) => {
const { isOpen, onToggle, onClose } = useDisclosure(); const { isOpen, onToggle, onClose } = useDisclosure();
return ( return (
...@@ -34,6 +38,7 @@ const Rating = ({ appId, rating, recordId, isRatedByUser, rate, isSending, isLoa ...@@ -34,6 +38,7 @@ const Rating = ({ appId, rating, recordId, isRatedByUser, rate, isSending, isLoa
fullView={ fullView } fullView={ fullView }
isActive={ isOpen } isActive={ isOpen }
onClick={ onToggle } onClick={ onToggle }
canRate={ canRate }
/> />
</PopoverTrigger> </PopoverTrigger>
<PopoverContent w="274px"> <PopoverContent w="274px">
......
import { Button, chakra, useColorModeValue } from '@chakra-ui/react'; import { Button, chakra, useColorModeValue, Tooltip } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import { useAccount } from 'wagmi';
import usePreventFocusAfterModalClosing from 'lib/hooks/usePreventFocusAfterModalClosing';
import IconSvg from 'ui/shared/IconSvg'; import IconSvg from 'ui/shared/IconSvg';
type Props = { type Props = {
...@@ -8,24 +10,46 @@ type Props = { ...@@ -8,24 +10,46 @@ type Props = {
fullView?: boolean; fullView?: boolean;
isActive: boolean; isActive: boolean;
onClick: () => void; onClick: () => void;
canRate: boolean;
}; };
const TriggerButton = ({ rating, fullView, isActive, onClick }: Props, ref: React.ForwardedRef<HTMLButtonElement>) => { const getTooltipText = (isWalletConnected: boolean, canRate: boolean) => {
if (!isWalletConnected) {
return <>You need a connected wallet to leave your rating.<br/>Link your wallet to Blockscout first</>;
}
if (!canRate) {
return <>New wallet users are not eligible to leave ratings.<br/>Please connect a different wallet</>;
}
return <>Ratings are derived from reviews by trusted users.<br/>Click here to rate!</>;
};
const TriggerButton = (
{ rating, fullView, isActive, onClick, canRate }: Props,
ref: React.ForwardedRef<HTMLButtonElement>,
) => {
const textColor = useColorModeValue('blackAlpha.800', 'whiteAlpha.800'); const textColor = useColorModeValue('blackAlpha.800', 'whiteAlpha.800');
const onFocusCapture = usePreventFocusAfterModalClosing();
const { address } = useAccount();
return ( return (
<Tooltip
label={ getTooltipText(Boolean(address), canRate) }
openDelay={ 100 }
textAlign="center"
>
<Button <Button
ref={ ref } ref={ ref }
size="xs" size="xs"
variant="outline" variant="outline"
border={ 0 } border={ 0 }
p={ 0 } p={ 0 }
onClick={ onClick } onClick={ canRate && Boolean(address) ? onClick : undefined }
fontSize={ fullView ? 'md' : 'sm' } fontSize={ fullView ? 'md' : 'sm' }
fontWeight={ fullView ? '400' : '500' } fontWeight={ fullView ? '400' : '500' }
lineHeight="21px" lineHeight="21px"
ml={ fullView ? 3 : 0 } ml={ fullView ? 3 : 0 }
isActive={ isActive } isActive={ isActive }
onFocusCapture={ onFocusCapture }
> >
{ !fullView && ( { !fullView && (
<IconSvg <IconSvg
...@@ -41,6 +65,7 @@ const TriggerButton = ({ rating, fullView, isActive, onClick }: Props, ref: Reac ...@@ -41,6 +65,7 @@ const TriggerButton = ({ rating, fullView, isActive, onClick }: Props, ref: Reac
'Rate it!' 'Rate it!'
) } ) }
</Button> </Button>
</Tooltip>
); );
}; };
......
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