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,
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);
}

View File

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

View File

@ -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 (
<SafeAreaView>
@ -85,9 +90,9 @@ const PostDisplayView = ({
<View style={styles.stickyWrapper}>
<Upvote
activeVotes={activeVotes}
fetchPost={fetchPost}
isShowPayoutValue
content={post}
incrementVoteCount={_handleIncrementActiveVotesCount}
/>
<TextWithIcon
iconName="heart-outline"
@ -95,7 +100,7 @@ const PostDisplayView = ({
iconType="MaterialCommunityIcons"
isClickable
onPress={() => handleOnVotersPress && handleOnVotersPress()}
text={activeVotes.length}
text={activeVotesCount}
textMarginLeft={20}
/>
<TextWithIcon

View File

@ -39,7 +39,7 @@ const UpvoteContainer = (props) => {
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');

View File

@ -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();
}
},

View File

@ -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;
});