From 3df4384360600d35f84fe8b7206eedab74a7906a Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Wed, 21 Aug 2019 14:54:49 +0300 Subject: [PATCH] Added downvote button for slider --- src/components/upvote/view/upvoteView.js | 95 +++++++++++++++--------- 1 file changed, 60 insertions(+), 35 deletions(-) diff --git a/src/components/upvote/view/upvoteView.js b/src/components/upvote/view/upvoteView.js index 145814f5a..9a74336e5 100644 --- a/src/components/upvote/view/upvoteView.js +++ b/src/components/upvote/view/upvoteView.js @@ -35,6 +35,7 @@ class UpvoteView extends Component { isVoted: get(props, 'isVoted', false), amount: '0.00000', isShowDetails: false, + downvote: false, }; } @@ -80,7 +81,7 @@ class UpvoteView extends Component { } }; - _upvoteContent = async () => { + _upvoteContent = async closePopover => { const { author, currentAccount, @@ -89,40 +90,55 @@ class UpvoteView extends Component { permlink, pinCode, } = this.props; - const { sliderValue } = this.state; + const { sliderValue, downvote } = this.state; - this.setState( - { - isVoting: true, - }, - () => { - handleSetUpvotePercent(sliderValue); - }, - ); + if (!downvote) { + closePopover(); + this.setState( + { + isVoting: true, + }, + () => { + handleSetUpvotePercent(sliderValue); + }, + ); - const weight = sliderValue ? (sliderValue * 100).toFixed(0) * 100 : 0; + const weight = sliderValue ? (sliderValue * 100).toFixed(0) * 100 : 0; - vote(currentAccount, pinCode, author, permlink, weight) - .then(() => { - this.setState( - { - isVoted: !!sliderValue, + vote(currentAccount, pinCode, author, permlink, weight) + .then(() => { + this.setState( + { + isVoted: !!sliderValue, + isVoting: false, + }, + () => { + if (fetchPost) { + fetchPost(); + } + }, + ); + }) + .catch(err => { + Alert.alert('Failed!', err.message); + this.setState({ + isVoted: false, isVoting: false, - }, - () => { - if (fetchPost) { - fetchPost(); - } - }, - ); - }) - .catch(err => { - Alert.alert('Failed!', err.message); - this.setState({ - isVoted: false, - isVoting: false, + }); }); - }); + } else { + this.setState({ sliderValue: 1, downvote: false }); + } + }; + + _downvoteContent = () => { + const { downvote } = this.state; + + if (downvote) { + // vote action + } + + this.setState({ sliderValue: 1, downvote: true }); }; _handleOnPopoverClose = () => { @@ -146,7 +162,7 @@ class UpvoteView extends Component { payoutDate, intl, } = this.props; - const { isVoting, amount, sliderValue, isVoted, isShowDetails } = this.state; + const { isVoting, amount, sliderValue, isVoted, isShowDetails, downvote } = this.state; let iconName = 'ios-arrow-dropup'; let iconType; @@ -156,9 +172,10 @@ class UpvoteView extends Component { iconType = 'AntDesign'; } - const _percent = `${(sliderValue * 100).toFixed(0)}%`; + const _percent = `${downvote ? '-' : ''}${(sliderValue * 100).toFixed(0)}%`; const _amount = `$${amount}`; const _totalPayout = totalPayout || '0.000'; + const _sliderColor = downvote ? '#ec8b88' : '#357ce6'; return ( @@ -253,8 +270,7 @@ class UpvoteView extends Component { { - closePopover(); - this._upvoteContent(); + this._upvoteContent(closePopover); }} style={styles.upvoteButton} > @@ -269,7 +285,7 @@ class UpvoteView extends Component { {_amount} {_percent} + + + )}