diff options
author | eug-vs <eug-vs@keemail.me> | 2020-06-25 14:38:23 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-06-25 14:38:23 +0300 |
commit | 1a7e205b615c4ba51aeb79a7c75cfc77290ba063 (patch) | |
tree | ad86f5b9cd9a80f052cdee1cd693f2399e23e41e | |
parent | 6212b5ef0e2ae1f2c2334bc003ead1d4fd0b1fe4 (diff) | |
download | which-ui-1a7e205b615c4ba51aeb79a7c75cfc77290ba063.tar.gz |
feat: highlight rateline correctly
-rw-r--r-- | src/components/PollCard/PollCard.tsx | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx index 06d33d5..6b5f456 100644 --- a/src/components/PollCard/PollCard.tsx +++ b/src/components/PollCard/PollCard.tsx @@ -8,6 +8,7 @@ import { CardHeader } from '@material-ui/core/'; import { Which, Poll } from 'which-types'; +import _ from 'lodash'; import PercentageBar from './PercentageBar'; import { post } from '../../requests'; @@ -35,7 +36,6 @@ const useStyles = makeStyles(theme => ({ }, rateLine: { position: 'relative', - margin: '0 auto', width: '100%', height: theme.spacing(2), backgroundColor: theme.palette.primary.light @@ -69,7 +69,12 @@ const PollCard: React.FC<PropTypes> = ({ initialPoll, navigate }) => { const handleRight = () => vote('right'); const leftPercentage = Math.round(100 * (left.votes / (left.votes + right.votes))); - const rightPercentage = 100 - leftPercentage; + + const percentage = { + left: leftPercentage, + right: 100 - leftPercentage + }; + const dominant: Which = left.votes >= right.votes ? 'left' : 'right'; return ( <Card className={classes.root}> @@ -91,18 +96,24 @@ const PollCard: React.FC<PropTypes> = ({ initialPoll, navigate }) => { className={classes.images} image={left.url} /> - <PercentageBar value={leftPercentage} which="left" like={userChoice === 'left'} /> + <PercentageBar value={percentage.left} which="left" like={userChoice === 'left'} /> </CardActionArea> <CardActionArea onDoubleClick={handleRight}> <CardMedia className={classes.images} image={right.url} /> - <PercentageBar value={rightPercentage} which="right" like={userChoice === 'right'} /> + <PercentageBar value={percentage.right} which="right" like={userChoice === 'right'} /> </CardActionArea> </div> <div className={classes.rateLine}> - <div className={classes.fillRateLine} style={{ width: `${leftPercentage}%` }} /> + <div + className={classes.fillRateLine} + style={{ + width: `${percentage[dominant]}%`, + float: dominant + }} + /> </div> </Card> ); |