Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed poll option lengths being calculated wrong if poll has 0 votes #314

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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