diff options
author | ilyayudovin <ilyayudovin123@gmail.com> | 2020-06-29 14:22:41 +0300 |
---|---|---|
committer | ilyayudovin <ilyayudovin123@gmail.com> | 2020-06-29 14:22:41 +0300 |
commit | 4037868a791c706c4d77d6353e396cb6454995be (patch) | |
tree | 5ac263f26a6b048b8692136184d4525e3aab1953 /src/components/PollCard/PollCard.tsx | |
parent | 447d864ef38c4e3acdbee0031c15c1f24473851e (diff) | |
download | which-ui-4037868a791c706c4d77d6353e396cb6454995be.tar.gz |
fix: show zero percentage instead of NaN
Diffstat (limited to 'src/components/PollCard/PollCard.tsx')
-rw-r--r-- | src/components/PollCard/PollCard.tsx | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx index d3b4fc2..f222a63 100644 --- a/src/components/PollCard/PollCard.tsx +++ b/src/components/PollCard/PollCard.tsx @@ -72,8 +72,13 @@ const PollCard: React.FC<PropTypes> = ({ initialPoll, navigate }) => { const handleLeft = () => vote('left'); const handleRight = () => vote('right'); - const leftPercentage = Math.round(100 * (left.votes / (left.votes + right.votes))); - const rightPercentage = 100 - leftPercentage; + let leftPercentage = Math.round(100 * (left.votes / (left.votes + right.votes))); + let rightPercentage = 100 - leftPercentage; + + if(Number.isNaN(leftPercentage) && Number.isNaN(rightPercentage)){ + leftPercentage = 0; + rightPercentage = 0; + } const dominant: Which = left.votes >= right.votes ? 'left' : 'right'; |