From 8c06adcb2d79a9966003760eebf21388b35d2b4d Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 28 Jun 2020 18:50:10 +0300 Subject: feat: migrate to new Poll interface --- package-lock.json | 6 +++--- package.json | 2 +- src/components/PollCard/PollCard.tsx | 18 +++++++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 84e7815..e7f7059 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14118,9 +14118,9 @@ "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" }, "which-types": { - "version": "1.4.2", - "resolved": "https://registry.npmjs.org/which-types/-/which-types-1.4.2.tgz", - "integrity": "sha512-nwcohvhH+VEA11cReLi/BgeuKHJYH7VM2BWe9OIX89CB+iaZ0+wb6oLFcIP6Vp6jw3k93yoPMe9pMBsOi4kj6w==" + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/which-types/-/which-types-1.6.1.tgz", + "integrity": "sha512-uTCrp6+rbU48kyT9Z6upVo9CgGmiR50zFSwzDik8slE8oZ+0FC9SBEfJlfgADX/rFJVbIe8Vxsw4BsSxlL5Lsw==" }, "word-wrap": { "version": "1.2.3", diff --git a/package.json b/package.json index ca1967a..f75c0e8 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "react-icons": "^3.10.0", "react-scripts": "3.4.1", "typeface-roboto": "0.0.75", - "which-types": "^1.4.2" + "which-types": "^1.6.1" }, "scripts": { "start": "react-scripts start", 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 = ({ initialPoll, navigate }) => { const [poll, setPoll] = useState(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 = ({ initialPoll, navigate }) => { className={classes.images} image={left.url} /> - + - +
-- cgit v1.2.3