From 782d0a093c63be47850e3ee9f87e948179a1251c Mon Sep 17 00:00:00 2001 From: Paul Jung Date: Wed, 25 Sep 2024 21:00:18 -0400 Subject: [PATCH] WV-542 Created Tooltip for liking and disliking a candidate --- .../HeartFavoriteToggleBase.jsx | 131 +++++++++++++----- 1 file changed, 95 insertions(+), 36 deletions(-) diff --git a/src/js/common/components/Widgets/HeartFavoriteToggle/HeartFavoriteToggleBase.jsx b/src/js/common/components/Widgets/HeartFavoriteToggle/HeartFavoriteToggleBase.jsx index fb01a5885..46353ac57 100644 --- a/src/js/common/components/Widgets/HeartFavoriteToggle/HeartFavoriteToggleBase.jsx +++ b/src/js/common/components/Widgets/HeartFavoriteToggle/HeartFavoriteToggleBase.jsx @@ -3,6 +3,9 @@ import PropTypes from 'prop-types'; import styled from 'styled-components'; import { Button } from '@mui/material'; import Popover from '@mui/material/Popover'; +import OverlayTrigger from 'react-bootstrap/OverlayTrigger'; +import isMobileScreenSize from '../../../../common/utils/isMobileScreenSize'; +import Tooltip from 'react-bootstrap/Tooltip'; import Typography from '@mui/material/Typography'; import CampaignActions from '../../../actions/CampaignActions'; import DesignTokenColors from '../../Style/DesignTokenColors'; @@ -259,6 +262,42 @@ class HeartFavoriteToggleBase extends Component { }); } + supportHoverText = () => { + const { campaignXWeVoteId, voterIsSignedIn } = this.props; + const { + campaignXOpposersCountLocal: campaignXOpposersCountLocalPrevious, + campaignXSupportersCountLocal: campaignXSupportersCountLocalPrevious, + voterOpposesLocal: voterOpposesLocalPrevious, + voterSupportsLocal: voterSupportsLocalPrevious, + } = this.state; + + if (!voterOpposesLocalPrevious && !voterSupportsLocalPrevious) { + return "Favoriting helps us show you what other candidates match your values."; + } else if (voterOpposesLocalPrevious) { + return "Favorited by " + campaignXSupportersCountLocalPrevious + " people. Favoriting helps us show you what other candidates match your values."; + } else { + return "Remove Favorite"; + } + } + + opposeHoverText = () => { + const { campaignXWeVoteId, voterIsSignedIn } = this.props; + const { + campaignXOpposersCountLocal: campaignXOpposersCountLocalPrevious, + campaignXSupportersCountLocal: campaignXSupportersCountLocalPrevious, + voterOpposesLocal: voterOpposesLocalPrevious, + voterSupportsLocal: voterSupportsLocalPrevious, + } = this.state; + + if (!voterOpposesLocalPrevious && !voterSupportsLocalPrevious) { + return "Disliking helps us show you what other candidates match your values."; + } else if (voterSupportsLocalPrevious) { + return "Disliked by " + campaignXOpposersCountLocalPrevious + " people. Disliking helps us show you what other candidates match your values."; + } else { + return "Remove Dislike"; + } + } + render () { const { voterIsSignedIn, @@ -277,47 +316,67 @@ class HeartFavoriteToggleBase extends Component { const open = Boolean(anchorEl); const id = open ? 'simple-popover' : undefined; + const supportToolTip = isMobileScreenSize() ? () : ( + +
+ {this.supportHoverText()} +
+
+ ); + + const opposeToolTip = isMobileScreenSize() ? () : ( + +
+ {this.opposeHoverText()} +
+
+ ); + // console.log('campaignXSupportersCountLocal', campaignXSupportersCountLocal, 'campaignXOpposersCountLocal', campaignXOpposersCountLocal); // console.log('HeartFavoriteToggleBase voterSupportsLocal', voterSupportsLocal, 'voterOpposesLocal', voterOpposesLocal); return ( - { - if (voterSupportsLocal) { - return this.handleStopSupportingClick(event); - } else { - return this.handleSupportClick(event); - } - }} - > - - {!voterOpposesLocal && ( - - {numberWithCommas(campaignXSupportersCountLocal)} - - )} - + + { + if (voterSupportsLocal) { + return this.handleStopSupportingClick(event); + } else { + return this.handleSupportClick(event); + } + }} + > + + {!voterOpposesLocal && ( + + {numberWithCommas(campaignXSupportersCountLocal)} + + )} + +   - { - if (voterOpposesLocal) { - return this.handleStopOpposingClick(event); - } else { - return this.handleOpposeClick(event); - } - }} - > - - {voterOpposesLocal && ( - - {numberWithCommas(campaignXOpposersCountLocal)} - - )} - + + { + if (voterOpposesLocal) { + return this.handleStopOpposingClick(event); + } else { + return this.handleOpposeClick(event); + } + }} + > + + {voterOpposesLocal && ( + + {numberWithCommas(campaignXOpposersCountLocal)} + + )} + + {(!voterIsSignedIn && (showSignInPromptOpposes || showSignInPromptSupports)) && (