From 1701e25b748b2fafe752d89802f7c88c533713ca Mon Sep 17 00:00:00 2001 From: Sebastian-Webster <84299475+Sebastian-Webster@users.noreply.github.com> Date: Mon, 1 Jan 2024 23:05:11 +1300 Subject: [PATCH] Fixed poll option lengths being calculated wrong if poll has 0 votes --- components/Posts/PollWithVotes.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/components/Posts/PollWithVotes.js b/components/Posts/PollWithVotes.js index 57b06dc..78b2463 100644 --- a/components/Posts/PollWithVotes.js +++ b/components/Posts/PollWithVotes.js @@ -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 ( <>