WIP voters info improvements fetch on click

This commit is contained in:
feruz 2020-10-16 00:51:16 +03:00
parent 8caffffc82
commit 440093ebe9
4 changed files with 42 additions and 11 deletions

View File

@ -29,6 +29,7 @@ const PostCardContainer = ({
nsfw,
}) => {
const [activeVotes, setActiveVotes] = useState([]);
const [totalVotes, setTotalVotes] = useState(0);
const [reblogs, setReblogs] = useState([]);
const [_content, setContent] = useState(null);
@ -40,14 +41,7 @@ const PostCardContainer = ({
useEffect(() => {
if (content) {
getActiveVotes(get(content, 'author'), get(content, 'permlink'))
.then((result) => {
result.sort((a, b) => b.rshares - a.rshares);
const _votes = parseActiveVotes({ ...content, active_votes: result });
setActiveVotes(_votes);
})
.catch(() => {});
setTotalVotes(get(content, 'stats.total_votes', 0));
getPostReblogs(content).then((result) => {
setReblogs(result);
@ -85,6 +79,7 @@ const PostCardContainer = ({
routeName: ROUTES.SCREENS.VOTERS,
params: {
activeVotes,
content,
},
key: get(content, 'permlink'),
});
@ -121,6 +116,7 @@ const PostCardContainer = ({
isHideImage={isHideImage}
isNsfwPost={nsfw === '1'}
activeVotes={activeVotes}
totalVotes={totalVotes}
reblogs={reblogs}
/>
);

View File

@ -33,9 +33,11 @@ const PostCardView = ({
isNsfwPost,
intl,
activeVotes,
totalVotes,
}) => {
const [rebloggedBy, setRebloggedBy] = useState(get(content, 'reblogged_by[0]', null));
const [activeVot, setActiveVot] = useState(activeVotes);
const [netVotes, setNetVotes] = useState(totalVotes);
// Component Functions
@ -77,6 +79,9 @@ const PostCardView = ({
if (activeVotes) {
setActiveVot(get(content, 'active_votes'));
}
if (totalVotes) {
setNetVotes(totalVotes);
}
}, [content]);
const _image = _getPostImage(content, isNsfwPost);
@ -132,7 +137,7 @@ const PostCardView = ({
iconStyle={styles.commentIcon}
iconType="MaterialCommunityIcons"
isClickable
text={activeVot.length}
text={netVotes}
onPress={_handleOnVotersPress}
/>
</TouchableOpacity>

View File

@ -18,6 +18,15 @@ import styles from './votersDisplayStyles';
const VotersDisplayView = ({ votes, navigation }) => {
const intl = useIntl();
/*getActiveVotes(get(content, 'author'), get(content, 'permlink'))
.then((result) => {
result.sort((a, b) => b.rshares - a.rshares);
const _votes = parseActiveVotes({ ...content, active_votes: result });
setActiveVotes(_votes);
})
.catch(() => {});*/
const _handleOnUserPress = (username) => {
navigation.navigate({
routeName: ROUTES.SCREENS.PROFILE,

View File

@ -1,4 +1,4 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import { SafeAreaView } from 'react-native';
import { useIntl } from 'react-intl';
import get from 'lodash/get';
@ -10,16 +10,37 @@ import AccountListContainer from '../../../containers/accountListContainer';
// Utils
import globalStyles from '../../../globalStyles';
import { getPost } from '../../../providers/steem/dsteem';
import { parseActiveVotes } from '../../../utils/postParser';
const filterOptions = ['rewards', 'percent', 'time'];
const VotersScreen = ({ navigation }) => {
const intl = useIntl();
const [activeVotes, setActiveVotes] = useState([]);
const [content, setContent] = useState(get(navigation, 'state.params.content'));
const [isLoading, setIsLoading] = useState(false);
const headerTitle = intl.formatMessage({
id: 'voters.voters_info',
});
const activeVotes = get(navigation, 'state.params.activeVotes');
useEffect(() => {
if (content) {
getPost(content.author, content.permlink)
.then((items) => {
items.active_votes.sort((a, b) => b.rshares - a.rshares);
const _votes = parseActiveVotes(items);
setActiveVotes(_votes);
})
.catch((err) => {
console.error(err.message);
});
}
}, []);
//const activeVotes = get(navigation, 'state.params.activeVotes');
//const content = get(navigation, 'state.params.content');
return (
<AccountListContainer data={activeVotes}>