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

Added storedCredentials check for voting in Polls #208

Merged
Merged
Show file tree
Hide file tree
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
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