From 8cb950adb0cb9119c3cc94a2fd74c416f9e7369b Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Wed, 3 Mar 2021 19:25:26 +0500 Subject: [PATCH] updated vote updater in post detail section --- .../postCard/container/postCardContainer.js | 3 +-- src/components/postCard/view/postCardView.js | 5 ++--- .../postView/view/postDisplayView.js | 9 ++++++-- .../upvote/container/upvoteContainer.js | 15 +++++++------ src/components/upvote/view/upvoteView.js | 21 +++++++++---------- src/providers/hive/dhive.js | 2 +- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/components/postCard/container/postCardContainer.js b/src/components/postCard/container/postCardContainer.js index b266f4bf7..3335a1059 100644 --- a/src/components/postCard/container/postCardContainer.js +++ b/src/components/postCard/container/postCardContainer.js @@ -28,7 +28,6 @@ const PostCardContainer = ({ isHideImage, nsfw, }) => { - const [_content, setContent] = useState(content); const [reblogs, setReblogs] = useState([]); const [activeVotes, setActiveVotes] = useState(get(_content, 'active_votes', [])); @@ -58,7 +57,7 @@ const PostCardContainer = ({ } }; - if (_content) { + if (_content) { fetchData(_content); } diff --git a/src/components/postCard/view/postCardView.js b/src/components/postCard/view/postCardView.js index 85dfc7189..a5baae94b 100644 --- a/src/components/postCard/view/postCardView.js +++ b/src/components/postCard/view/postCardView.js @@ -67,9 +67,8 @@ const PostCardView = ({ }; const _handleIncrementVoteCount = () => { - setActiveVotesCount(activeVotesCount + 1) - } - + setActiveVotesCount(activeVotesCount + 1); + }; // useEffect(() => { // if (content) { diff --git a/src/components/postView/view/postDisplayView.js b/src/components/postView/view/postDisplayView.js index cc7a44b06..38687f545 100644 --- a/src/components/postView/view/postDisplayView.js +++ b/src/components/postView/view/postDisplayView.js @@ -46,6 +46,7 @@ const PostDisplayView = ({ const [isLoadedComments, setIsLoadedComments] = useState(false); const actionSheet = useRef(null); const [refreshing, setRefreshing] = useState(false); + const [activeVotesCount, setActiveVotesCount] = useState(activeVotes.length || 0) // Component Life Cycles useEffect(() => { @@ -78,6 +79,10 @@ const PostDisplayView = ({ } }; + const _handleIncrementActiveVotesCount = () =>{ + setActiveVotesCount(activeVotesCount + 1); + } + const _getTabBar = (isFixedFooter = false) => { return ( @@ -85,9 +90,9 @@ const PostDisplayView = ({ handleOnVotersPress && handleOnVotersPress()} - text={activeVotes.length} + text={activeVotesCount} textMarginLeft={20} /> { const [isVoted, setIsVoted] = useState(null); const [isDownVoted, setIsDownVoted] = useState(null); - const [totalPayout, setTotalPayout] = useState(get(content, 'total_payout')) + const [totalPayout, setTotalPayout] = useState(get(content, 'total_payout')); useEffect(() => { _calculateVoteStatus(); @@ -64,19 +64,18 @@ const UpvoteContainer = (props) => { //do all relevant processing here to show local upvote const amountNum = parseFloat(amount); - setTotalPayout(totalPayout + amountNum) + setTotalPayout(totalPayout + amountNum); - if(!isVoted && !isDownVoted && incrementVoteCount){ - incrementVoteCount() + if (!isVoted && !isDownVoted && incrementVoteCount) { + incrementVoteCount(); } - if(isDownvote){ + if (isDownvote) { setIsDownVoted(true); - }else{ + } else { setIsVoted(true); } - - } + }; const author = get(content, 'author'); const isDecinedPayout = get(content, 'is_declined_payout'); diff --git a/src/components/upvote/view/upvoteView.js b/src/components/upvote/view/upvoteView.js index a091f365b..94dfa2025 100644 --- a/src/components/upvote/view/upvoteView.js +++ b/src/components/upvote/view/upvoteView.js @@ -76,7 +76,7 @@ class UpvoteView extends Component { fetchPost, onVote, } = this.props; - const { sliderValue, downvote, amount} = this.state; + const { sliderValue, downvote, amount } = this.state; if (!downvote) { closePopover(); @@ -91,7 +91,7 @@ class UpvoteView extends Component { const weight = sliderValue ? (sliderValue * 100).toFixed(0) * 100 : 0; - console.log("casting up vote: " + weight); + console.log('casting up vote: ' + weight); vote(currentAccount, pinCode, author, permlink, weight) .then(() => { this.setState( @@ -101,11 +101,11 @@ class UpvoteView extends Component { }, () => { //add snippet to update amount and active vote count - - onVote(amount, false) - + + onVote(amount, false); + if (fetchPost) { - console.log("fetching post") + console.log('fetching post'); fetchPost(); } }, @@ -188,8 +188,8 @@ class UpvoteView extends Component { ); const weight = sliderValue ? (sliderValue * 100).toFixed(0) * 100 * -1 : 0; - - console.log("casting down vote: " + weight); + + console.log('casting down vote: ' + weight); vote(currentAccount, pinCode, author, permlink, weight) .then(() => { this.setState( @@ -198,11 +198,10 @@ class UpvoteView extends Component { isVoting: false, }, () => { - - onVote(amount, true) + onVote(amount, true); if (fetchPost) { - console.log("Fetching post") + console.log('Fetching post'); fetchPost(); } }, diff --git a/src/providers/hive/dhive.js b/src/providers/hive/dhive.js index 93b5078f2..3df129ea7 100644 --- a/src/providers/hive/dhive.js +++ b/src/providers/hive/dhive.js @@ -649,7 +649,7 @@ export const signImage = async (file, currentAccount, pin) => { export const vote = (account, pin, author, permlink, weight) => _vote(account, pin, author, permlink, weight).then((resp) => { userActivity(account.username, 120, resp.block_num, resp.id); - console.log("Returning vote response"); + console.log('Returning vote response'); return resp; });