Skip to content

Commit

Permalink
Merge pull request #208 from SquareTable/190-add-storedcredentials-ch…
Browse files Browse the repository at this point in the history
…eck-to-pollpost-when-voting

Added storedCredentials check for voting in Polls
  • Loading branch information
Sebastian-Webster authored Sep 21, 2023
2 parents e0bffc4 + 81dca66 commit 9b99903
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
22 changes: 16 additions & 6 deletions components/Posts/PollPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ class Poll extends Component {
})
}

upvote = () => {
runIfAuthenticated = (func) => {
return () => {
if (this.props.userId === 'SSGUEST' || !this.props.userId) {
this.props.navigation.navigate('ModalLoginScreen', {modal: true})
} else {
func()
}
}
}

upvote = this.runIfAuthenticated(() => {
if (!this.props.post.changingVote) {
this.handleStartVoteChange()

Expand Down Expand Up @@ -86,9 +96,9 @@ class Poll extends Component {
console.error('An error occured while upvoting poll post:', error)
})
}
}
})

downvote = () => {
downvote = this.runIfAuthenticated(() => {
if (!this.props.post.changingVote) {
this.handleStartVoteChange();

Expand Down Expand Up @@ -121,7 +131,7 @@ class Poll extends Component {
console.error('An error occured while downvoting poll post:', error)
})
}
}
})

shouldComponentUpdate(nextProps, nextState) {
const upvoteIsSame = nextProps.post.upvoted === this.props.post.upvoted;
Expand All @@ -145,7 +155,7 @@ class Poll extends Component {
})
}

openThreeDotsMenu = () => {
openThreeDotsMenu = this.runIfAuthenticated(() => {
if (this.props.post.isOwner !== true && this.props.post.isOwner !== false) {
alert("isOwner is not true or false. An error has occured.")
return
Expand All @@ -158,7 +168,7 @@ class Poll extends Component {
isOwner: this.props.post.isOwner,
postIndex: this.props.index
})
}
})

render() {
return (
Expand Down
22 changes: 0 additions & 22 deletions components/Posts/PollWithVotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ class PollWithVotes extends PollClass {
this.props.dispatch({type: 'openPollVoteMenu', openPollVoteMenu: "Six", postIndex: this.props.index})
}

optionOneInfoState = false; //Temporary
optionTwoInfoState = false; //Temporary
optionThreeInfoState = false; //Temporary
optionFourInfoState = false; //Temporary
optionFiveInfoState = false; //Temporary
optionSixInfoState = false; //Temporary

handleVoteOnPoll = (optionSelected, voteNumber) => {
if (this.props.storedCredentials) {
this.props.dispatch({type: 'startPollVoteChange', postIndex: this.props.index})
Expand Down Expand Up @@ -131,21 +124,6 @@ class PollWithVotes extends PollClass {
return true;
}

openThreeDotsMenu = () => {
if (this.props.post.isOwner !== true && this.props.post.isOwner !== false) {
alert("isOwner is not true or false. An error has occured.")
return
}

this.props.dispatch({
type: 'showMenu',
postId: this.props.post._id,
postFormat: 'Poll',
isOwner: this.props.post.isOwner,
postIndex: this.props.index
})
}

render() {
return (
<>
Expand Down

0 comments on commit 9b99903

Please sign in to comment.