diff options
author | Eugene Sokolov <eug-vs@keemail.me> | 2020-06-28 18:56:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-28 18:56:38 +0300 |
commit | 699c702ca941c0e7e5fdcb971c9135e28b80c221 (patch) | |
tree | 782231cf1b155acbbedcf2642628b9e6d2f008c4 /src/components | |
parent | ccb26a42a3ad8d748e00cfbe9687f3198d5b8cb4 (diff) | |
parent | 8c06adcb2d79a9966003760eebf21388b35d2b4d (diff) | |
download | which-ui-699c702ca941c0e7e5fdcb971c9135e28b80c221.tar.gz |
Merge pull request #51 from which-ecosystem/votes-update
Migrate to new Poll interface
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/PollCard/PollCard.tsx | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx index d3b4fc2..caa2de1 100644 --- a/src/components/PollCard/PollCard.tsx +++ b/src/components/PollCard/PollCard.tsx @@ -57,20 +57,20 @@ const useStyles = makeStyles(theme => ({ const PollCard: React.FC<PropTypes> = ({ initialPoll, navigate }) => { const [poll, setPoll] = useState<Poll>(initialPoll); const classes = useStyles(); - const { author, contents: { left, right }, userChoice } = poll; + const { author, contents: { left, right }, vote } = poll; const date: string = new Date(poll.createdAt).toLocaleString('default', DATE_FORMAT); - const vote = (which: Which) => { - if (userChoice) return; - post('votes/', { which, pollId: poll._id }).then(() => { + const handleVote = (which: Which) => { + if (vote) return; + post('votes/', { which, pollId: poll._id }).then(response => { poll.contents[which].votes += 1; - poll.userChoice = which; + poll.vote = response.data; setPoll({ ...poll }); }); }; - const handleLeft = () => vote('left'); - const handleRight = () => vote('right'); + const handleLeft = () => handleVote('left'); + const handleRight = () => handleVote('right'); const leftPercentage = Math.round(100 * (left.votes / (left.votes + right.votes))); const rightPercentage = 100 - leftPercentage; @@ -86,14 +86,14 @@ const PollCard: React.FC<PropTypes> = ({ initialPoll, navigate }) => { className={classes.images} image={left.url} /> - <PercentageBar value={leftPercentage} which="left" like={userChoice === 'left'} /> + <PercentageBar value={leftPercentage} which="left" like={vote?.which === 'left'} /> </CardActionArea> <CardActionArea onDoubleClick={handleRight}> <CardMedia className={classes.images} image={right.url} /> - <PercentageBar value={rightPercentage} which="right" like={userChoice === 'right'} /> + <PercentageBar value={rightPercentage} which="right" like={vote?.which === 'right'} /> </CardActionArea> </div> <div className={`${classes.rateLine} ${dominant === 'right' ? classes.highlight : ''}`}> |