Skip to content

Commit

Permalink
Merge pull request #314 from SquareTable/313-polls-with-0-votes-have-…
Browse files Browse the repository at this point in the history
…option-lengths-calculated-wrong

Fixed poll option lengths being calculated wrong if poll has 0 votes
  • Loading branch information
Sebastian-Webster authored Jan 1, 2024
2 parents 97cbcf1 + 1701e25 commit 4a119b7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions components/Posts/PollWithVotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,25 @@ class PollWithVotes extends PollClass {
'Six': 6
}

numberOfOptions = this.voteTextToNumberObject[this.props.post.totalNumberOfOptions]

calculateZeroVoteLength = (optionNumber) => {
if (optionNumber <= this.numberOfOptions) return 100 / this.numberOfOptions
return 0
}

navigateToProfileScreen = () => {
this.props.navigation.navigate('ProfilePages', {pubId: this.props.post.creatorPublicId})
}

render() {
this.votes = this.props.post.optionOnesVotes + this.props.post.optionTwosVotes + this.props.post.optionThreesVotes + this.props.post.optionFoursVotes + this.props.post.optionFivesVotes + this.props.post.optionSixesVotes;
this.optionOnesBarLength = this.votes === 0 ? this.voteTextToNumberObject[this.props.post.totalNumberOfOptions] / 100 : this.props.post.optionOnesVotes / this.votes * 100
this.optionTwosBarLength = this.votes === 0 ? this.voteTextToNumberObject[this.props.post.totalNumberOfOptions] / 100 : this.props.post.optionTwosVotes / this.votes * 100
this.optionThreesBarLength = this.votes === 0 ? this.voteTextToNumberObject[this.props.post.totalNumberOfOptions] / 100 : this.props.post.optionThreesVotes / this.votes * 100
this.optionFoursBarLength = this.votes === 0 ? this.voteTextToNumberObject[this.props.post.totalNumberOfOptions] / 100 : this.props.post.optionFoursVotes / this.votes * 100
this.optionFivesBarLength = this.votes === 0 ? this.voteTextToNumberObject[this.props.post.totalNumberOfOptions] / 100 : this.props.post.optionFivesVotes / this.votes * 100
this.optionSixesBarLength = this.votes === 0 ? this.voteTextToNumberObject[this.props.post.totalNumberOfOptions] / 100 : this.props.post.optionSixesVotes / this.votes * 100
this.optionOnesBarLength = this.votes === 0 ? this.calculateZeroVoteLength(1) : this.props.post.optionOnesVotes / this.votes * 100
this.optionTwosBarLength = this.votes === 0 ? this.calculateZeroVoteLength(2) : this.props.post.optionTwosVotes / this.votes * 100
this.optionThreesBarLength = this.votes === 0 ? this.calculateZeroVoteLength(3) : this.props.post.optionThreesVotes / this.votes * 100
this.optionFoursBarLength = this.votes === 0 ? this.calculateZeroVoteLength(4) : this.props.post.optionFoursVotes / this.votes * 100
this.optionFivesBarLength = this.votes === 0 ? this.calculateZeroVoteLength(5) : this.props.post.optionFivesVotes / this.votes * 100
this.optionSixesBarLength = this.votes === 0 ? this.calculateZeroVoteLength(6) : this.props.post.optionSixesVotes / this.votes * 100

return (
<>
Expand Down

0 comments on commit 4a119b7

Please sign in to comment.