From 50c4be486b65454a0d08653a679b265f156e04d3 Mon Sep 17 00:00:00 2001 From: Sebastian Webster Date: Thu, 21 Sep 2023 21:52:17 +1200 Subject: [PATCH 1/3] Added storedCredentials check when up/downvoting on polls --- components/Posts/PollPost.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/components/Posts/PollPost.js b/components/Posts/PollPost.js index 478c0eb..d23d488 100644 --- a/components/Posts/PollPost.js +++ b/components/Posts/PollPost.js @@ -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() @@ -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(); @@ -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; @@ -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 @@ -158,7 +168,7 @@ class Poll extends Component { isOwner: this.props.post.isOwner, postIndex: this.props.index }) - } + }) render() { return ( From d078d61707f9830b6e49ea36b4e52337a12d183c Mon Sep 17 00:00:00 2001 From: Sebastian Webster Date: Thu, 21 Sep 2023 21:53:03 +1200 Subject: [PATCH 2/3] Removed unneccesary code --- components/Posts/PollWithVotes.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/components/Posts/PollWithVotes.js b/components/Posts/PollWithVotes.js index 207a53d..f926188 100644 --- a/components/Posts/PollWithVotes.js +++ b/components/Posts/PollWithVotes.js @@ -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}) From 81dca665d74dc14fdd70b6514c2d7ce6c8a3c728 Mon Sep 17 00:00:00 2001 From: Sebastian Webster Date: Thu, 21 Sep 2023 21:54:12 +1200 Subject: [PATCH 3/3] openThreeDotsMenu now has storedCredentials check --- components/Posts/PollWithVotes.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/components/Posts/PollWithVotes.js b/components/Posts/PollWithVotes.js index f926188..4026794 100644 --- a/components/Posts/PollWithVotes.js +++ b/components/Posts/PollWithVotes.js @@ -124,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 ( <>