updated vote updater in post detail section

This commit is contained in:
Nouman Tahir 2021-03-03 19:25:26 +05:00
parent 8fa48fca62
commit 8cb950adb0
6 changed files with 28 additions and 27 deletions

View File

@ -28,7 +28,6 @@ const PostCardContainer = ({
isHideImage, isHideImage,
nsfw, nsfw,
}) => { }) => {
const [_content, setContent] = useState(content); const [_content, setContent] = useState(content);
const [reblogs, setReblogs] = useState([]); const [reblogs, setReblogs] = useState([]);
const [activeVotes, setActiveVotes] = useState(get(_content, 'active_votes', [])); const [activeVotes, setActiveVotes] = useState(get(_content, 'active_votes', []));

View File

@ -67,9 +67,8 @@ const PostCardView = ({
}; };
const _handleIncrementVoteCount = () => { const _handleIncrementVoteCount = () => {
setActiveVotesCount(activeVotesCount + 1) setActiveVotesCount(activeVotesCount + 1);
} };
// useEffect(() => { // useEffect(() => {
// if (content) { // if (content) {

View File

@ -46,6 +46,7 @@ const PostDisplayView = ({
const [isLoadedComments, setIsLoadedComments] = useState(false); const [isLoadedComments, setIsLoadedComments] = useState(false);
const actionSheet = useRef(null); const actionSheet = useRef(null);
const [refreshing, setRefreshing] = useState(false); const [refreshing, setRefreshing] = useState(false);
const [activeVotesCount, setActiveVotesCount] = useState(activeVotes.length || 0)
// Component Life Cycles // Component Life Cycles
useEffect(() => { useEffect(() => {
@ -78,6 +79,10 @@ const PostDisplayView = ({
} }
}; };
const _handleIncrementActiveVotesCount = () =>{
setActiveVotesCount(activeVotesCount + 1);
}
const _getTabBar = (isFixedFooter = false) => { const _getTabBar = (isFixedFooter = false) => {
return ( return (
<SafeAreaView> <SafeAreaView>
@ -85,9 +90,9 @@ const PostDisplayView = ({
<View style={styles.stickyWrapper}> <View style={styles.stickyWrapper}>
<Upvote <Upvote
activeVotes={activeVotes} activeVotes={activeVotes}
fetchPost={fetchPost}
isShowPayoutValue isShowPayoutValue
content={post} content={post}
incrementVoteCount={_handleIncrementActiveVotesCount}
/> />
<TextWithIcon <TextWithIcon
iconName="heart-outline" iconName="heart-outline"
@ -95,7 +100,7 @@ const PostDisplayView = ({
iconType="MaterialCommunityIcons" iconType="MaterialCommunityIcons"
isClickable isClickable
onPress={() => handleOnVotersPress && handleOnVotersPress()} onPress={() => handleOnVotersPress && handleOnVotersPress()}
text={activeVotes.length} text={activeVotesCount}
textMarginLeft={20} textMarginLeft={20}
/> />
<TextWithIcon <TextWithIcon

View File

@ -39,7 +39,7 @@ const UpvoteContainer = (props) => {
const [isVoted, setIsVoted] = useState(null); const [isVoted, setIsVoted] = useState(null);
const [isDownVoted, setIsDownVoted] = useState(null); const [isDownVoted, setIsDownVoted] = useState(null);
const [totalPayout, setTotalPayout] = useState(get(content, 'total_payout')) const [totalPayout, setTotalPayout] = useState(get(content, 'total_payout'));
useEffect(() => { useEffect(() => {
_calculateVoteStatus(); _calculateVoteStatus();
@ -64,19 +64,18 @@ const UpvoteContainer = (props) => {
//do all relevant processing here to show local upvote //do all relevant processing here to show local upvote
const amountNum = parseFloat(amount); const amountNum = parseFloat(amount);
setTotalPayout(totalPayout + amountNum) setTotalPayout(totalPayout + amountNum);
if(!isVoted && !isDownVoted && incrementVoteCount){ if (!isVoted && !isDownVoted && incrementVoteCount) {
incrementVoteCount() incrementVoteCount();
} }
if(isDownvote){ if (isDownvote) {
setIsDownVoted(true); setIsDownVoted(true);
}else{ } else {
setIsVoted(true); setIsVoted(true);
} }
};
}
const author = get(content, 'author'); const author = get(content, 'author');
const isDecinedPayout = get(content, 'is_declined_payout'); const isDecinedPayout = get(content, 'is_declined_payout');

View File

@ -76,7 +76,7 @@ class UpvoteView extends Component {
fetchPost, fetchPost,
onVote, onVote,
} = this.props; } = this.props;
const { sliderValue, downvote, amount} = this.state; const { sliderValue, downvote, amount } = this.state;
if (!downvote) { if (!downvote) {
closePopover(); closePopover();
@ -91,7 +91,7 @@ class UpvoteView extends Component {
const weight = sliderValue ? (sliderValue * 100).toFixed(0) * 100 : 0; 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) vote(currentAccount, pinCode, author, permlink, weight)
.then(() => { .then(() => {
this.setState( this.setState(
@ -102,10 +102,10 @@ class UpvoteView extends Component {
() => { () => {
//add snippet to update amount and active vote count //add snippet to update amount and active vote count
onVote(amount, false) onVote(amount, false);
if (fetchPost) { if (fetchPost) {
console.log("fetching post") console.log('fetching post');
fetchPost(); fetchPost();
} }
}, },
@ -189,7 +189,7 @@ class UpvoteView extends Component {
const weight = sliderValue ? (sliderValue * 100).toFixed(0) * 100 * -1 : 0; 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) vote(currentAccount, pinCode, author, permlink, weight)
.then(() => { .then(() => {
this.setState( this.setState(
@ -198,11 +198,10 @@ class UpvoteView extends Component {
isVoting: false, isVoting: false,
}, },
() => { () => {
onVote(amount, true);
onVote(amount, true)
if (fetchPost) { if (fetchPost) {
console.log("Fetching post") console.log('Fetching post');
fetchPost(); fetchPost();
} }
}, },

View File

@ -649,7 +649,7 @@ export const signImage = async (file, currentAccount, pin) => {
export const vote = (account, pin, author, permlink, weight) => export const vote = (account, pin, author, permlink, weight) =>
_vote(account, pin, author, permlink, weight).then((resp) => { _vote(account, pin, author, permlink, weight).then((resp) => {
userActivity(account.username, 120, resp.block_num, resp.id); userActivity(account.username, 120, resp.block_num, resp.id);
console.log("Returning vote response"); console.log('Returning vote response');
return resp; return resp;
}); });