mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-19 11:21:41 +03:00
discarded useEffect hook and ImageSize calculator (for now)
This commit is contained in:
parent
c869587b6e
commit
4f5ece215a
@ -38,11 +38,13 @@ const PostCardView = ({
|
||||
intl,
|
||||
activeVotes,
|
||||
}) => {
|
||||
const [rebloggedBy, setRebloggedBy] = useState(get(content, 'reblogged_by[0]', null));
|
||||
const [activeVot, setActiveVot] = useState(activeVotes);
|
||||
const [calcImgHeight, setCalcImgHeight] = useState(300);
|
||||
const [images, setImages] = useState({});
|
||||
//console.log(activeVotes);
|
||||
// const [rebloggedBy, setRebloggedBy] = useState(get(content, 'reblogged_by[0]', null));
|
||||
// const [activeVot, setActiveVot] = useState(activeVotes);
|
||||
// const [images, setImages] = useState({});
|
||||
// const [calcImgHeight, setCalcImgHeight] = useState(300);
|
||||
const calcImgHeight = 300;
|
||||
|
||||
|
||||
// Component Functions
|
||||
|
||||
const _handleOnUserPress = () => {
|
||||
@ -65,44 +67,59 @@ const PostCardView = ({
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (content) {
|
||||
const _rebloggedBy = get(content, 'reblogged_by[0]', null);
|
||||
setRebloggedBy(_rebloggedBy);
|
||||
// useEffect(() => {
|
||||
// if (content) {
|
||||
// const _rebloggedBy = get(content, 'reblogged_by[0]', null);
|
||||
// setRebloggedBy(_rebloggedBy);
|
||||
|
||||
if (content.thumbnail) {
|
||||
if (isNsfwPost && content.nsfw) {
|
||||
setImages({ image: NSFW_IMAGE, thumbnail: NSFW_IMAGE });
|
||||
}
|
||||
//console.log(content)
|
||||
let ratio = 10 / 7;
|
||||
ImageSize.getSize(content.thumbnail)
|
||||
.then((size) => {
|
||||
ratio = size.height / size.width;
|
||||
setCalcImgHeight(Math.floor(ratio * (dim.width - 18)));
|
||||
})
|
||||
.catch((er) => {
|
||||
setCalcImgHeight(Math.floor(ratio * (dim.width - 18)));
|
||||
bugsnag.notify(er, (report) => {
|
||||
report.metadata = {
|
||||
content,
|
||||
};
|
||||
});
|
||||
});
|
||||
setImages({ image: content.image, thumbnail: content.thumbnail });
|
||||
} else {
|
||||
setImages({ image: DEFAULT_IMAGE, thumbnail: DEFAULT_IMAGE });
|
||||
}
|
||||
// if (content.thumbnail) {
|
||||
// if (isNsfwPost && content.nsfw) {
|
||||
// setImages({ image: NSFW_IMAGE, thumbnail: NSFW_IMAGE });
|
||||
// }
|
||||
// console.log(content)
|
||||
// let ratio = 10 / 7;
|
||||
// ImageSize.getSize(content.thumbnail)
|
||||
// .then((size) => {
|
||||
// ratio = size.height / size.width;
|
||||
// setCalcImgHeight(Math.floor(ratio * (dim.width - 18)));
|
||||
// })
|
||||
// .catch((er) => {
|
||||
// setCalcImgHeight(Math.floor(ratio * (dim.width - 18)));
|
||||
// bugsnag.notify(er, (report) => {
|
||||
// report.metadata = {
|
||||
// content,
|
||||
// };
|
||||
// });
|
||||
// });
|
||||
// setImages({ image: content.image, thumbnail: content.thumbnail });
|
||||
// }
|
||||
// else {
|
||||
// setImages({ image: DEFAULT_IMAGE, thumbnail: DEFAULT_IMAGE });
|
||||
// }
|
||||
|
||||
// if (activeVotes) {
|
||||
// setActiveVot(get(content, 'active_votes'));
|
||||
// }
|
||||
// }
|
||||
// return () => {
|
||||
// setImages({ image: DEFAULT_IMAGE, thumbnail: DEFAULT_IMAGE });
|
||||
// setCalcImgHeight(300);
|
||||
// setActiveVot([]);
|
||||
// };
|
||||
// }, []);
|
||||
|
||||
const activeVot = get(content, 'active_votes', []);
|
||||
const rebloggedBy = get(content, 'reblogged_by[0]', null);
|
||||
var images = { image: DEFAULT_IMAGE, thumbnail: DEFAULT_IMAGE };
|
||||
if (content.thumbnail) {
|
||||
if (isNsfwPost && content.nsfw) {
|
||||
images = { image: NSFW_IMAGE, thumbnail: NSFW_IMAGE };
|
||||
}
|
||||
if (activeVotes) {
|
||||
setActiveVot(get(content, 'active_votes'));
|
||||
}
|
||||
return () => {
|
||||
setImages({ image: DEFAULT_IMAGE, thumbnail: DEFAULT_IMAGE });
|
||||
setCalcImgHeight(300);
|
||||
setActiveVot([]);
|
||||
};
|
||||
}, [content]);
|
||||
|
||||
images = { image: content.image, thumbnail: content.thumbnail };
|
||||
} else {
|
||||
images = { image: DEFAULT_IMAGE, thumbnail: DEFAULT_IMAGE };
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={styles.post}>
|
||||
|
@ -39,16 +39,16 @@ const UpvoteContainer = (props) => {
|
||||
const [isDownVoted, setIsDownVoted] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
_calculateVoteStatus()
|
||||
}, [activeVotes])
|
||||
_calculateVoteStatus();
|
||||
}, [activeVotes]);
|
||||
|
||||
const _calculateVoteStatus = async () => {
|
||||
const _isVoted = await isVotedFunc(activeVotes, get(currentAccount, 'name'));
|
||||
const _isDownVoted = await isDownVotedFunc(activeVotes, get(currentAccount, 'name'));
|
||||
|
||||
setIsVoted(_isVoted && parseInt(_isVoted, 10) / 10000)
|
||||
setIsDownVoted(_isDownVoted && (parseInt(_isDownVoted, 10) / 10000) * -1)
|
||||
}
|
||||
setIsVoted(_isVoted && parseInt(_isVoted, 10) / 10000);
|
||||
setIsDownVoted(_isDownVoted && (parseInt(_isDownVoted, 10) / 10000) * -1);
|
||||
};
|
||||
|
||||
const _setUpvotePercent = (value) => {
|
||||
const { dispatch } = this.props;
|
||||
@ -59,85 +59,82 @@ const UpvoteContainer = (props) => {
|
||||
}
|
||||
};
|
||||
|
||||
const author = get(content, 'author');
|
||||
const totalPayout = get(content, 'total_payout');
|
||||
const isDecinedPayout = get(content, 'is_declined_payout');
|
||||
const permlink = get(content, 'permlink');
|
||||
const pendingPayout = parseAsset(content.pending_payout_value).amount;
|
||||
const authorPayout = parseAsset(content.author_payout_value).amount;
|
||||
const curationPayout = parseAsset(content.curator_payout_value).amount;
|
||||
const promotedPayout = parseAsset(content.promoted).amount;
|
||||
const payoutDate = getTimeFromNow(get(content, 'payout_at'));
|
||||
const beneficiaries = [];
|
||||
const beneficiary = get(content, 'beneficiaries');
|
||||
if (beneficiary) {
|
||||
beneficiary.forEach((key) => {
|
||||
beneficiaries.push(
|
||||
`\n ${get(key, 'account')}: ${(parseFloat(get(key, 'weight')) / 100).toFixed(2)}%`,
|
||||
);
|
||||
});
|
||||
}
|
||||
const minimumAmountForPayout = 0.02;
|
||||
let warnZeroPayout = false;
|
||||
if (pendingPayout > 0 && pendingPayout < minimumAmountForPayout) {
|
||||
warnZeroPayout = true;
|
||||
}
|
||||
const base = get(globalProps, 'base', 0);
|
||||
const quote = get(globalProps, 'quote', 0);
|
||||
const sbdPrintRate = get(globalProps, 'sbdPrintRate', 0);
|
||||
const SBD_PRINT_RATE_MAX = 10000;
|
||||
const percent_steem_dollars = (content.percent_hbd || 10000) / 20000;
|
||||
|
||||
const author = get(content, 'author');
|
||||
const totalPayout = get(content, 'total_payout');
|
||||
const isDecinedPayout = get(content, 'is_declined_payout');
|
||||
const permlink = get(content, 'permlink');
|
||||
const pendingPayout = parseAsset(content.pending_payout_value).amount;
|
||||
const authorPayout = parseAsset(content.author_payout_value).amount;
|
||||
const curationPayout = parseAsset(content.curator_payout_value).amount;
|
||||
const promotedPayout = parseAsset(content.promoted).amount;
|
||||
const payoutDate = getTimeFromNow(get(content, 'payout_at'));
|
||||
const beneficiaries = [];
|
||||
const beneficiary = get(content, 'beneficiaries');
|
||||
if (beneficiary) {
|
||||
beneficiary.forEach((key) => {
|
||||
beneficiaries.push(
|
||||
`\n ${get(key, 'account')}: ${(parseFloat(get(key, 'weight')) / 100).toFixed(2)}%`,
|
||||
);
|
||||
});
|
||||
}
|
||||
const minimumAmountForPayout = 0.02;
|
||||
let warnZeroPayout = false;
|
||||
if (pendingPayout > 0 && pendingPayout < minimumAmountForPayout) {
|
||||
warnZeroPayout = true;
|
||||
}
|
||||
const base = get(globalProps, 'base', 0);
|
||||
const quote = get(globalProps, 'quote', 0);
|
||||
const sbdPrintRate = get(globalProps, 'sbdPrintRate', 0);
|
||||
const SBD_PRINT_RATE_MAX = 10000;
|
||||
const percent_steem_dollars = (content.percent_hbd || 10000) / 20000;
|
||||
const pending_payout_hbd = pendingPayout * percent_steem_dollars;
|
||||
const price_per_steem = base / quote;
|
||||
|
||||
const pending_payout_hbd = pendingPayout * percent_steem_dollars;
|
||||
const price_per_steem = base / quote;
|
||||
const pending_payout_hp = (pendingPayout - pending_payout_hbd) / price_per_steem;
|
||||
const pending_payout_printed_hbd = pending_payout_hbd * (sbdPrintRate / SBD_PRINT_RATE_MAX);
|
||||
const pending_payout_printed_hive =
|
||||
(pending_payout_hbd - pending_payout_printed_hbd) / price_per_steem;
|
||||
|
||||
const pending_payout_hp = (pendingPayout - pending_payout_hbd) / price_per_steem;
|
||||
const pending_payout_printed_hbd = pending_payout_hbd * (sbdPrintRate / SBD_PRINT_RATE_MAX);
|
||||
const pending_payout_printed_hive =
|
||||
(pending_payout_hbd - pending_payout_printed_hbd) / price_per_steem;
|
||||
const breakdownPayout =
|
||||
pending_payout_printed_hbd.toFixed(3) +
|
||||
' HBD, ' +
|
||||
pending_payout_printed_hive.toFixed(3) +
|
||||
' HIVE, ' +
|
||||
pending_payout_hp.toFixed(3) +
|
||||
' HP';
|
||||
|
||||
const breakdownPayout =
|
||||
pending_payout_printed_hbd.toFixed(3) +
|
||||
' HBD, ' +
|
||||
pending_payout_printed_hive.toFixed(3) +
|
||||
' HIVE, ' +
|
||||
pending_payout_hp.toFixed(3) +
|
||||
' HP';
|
||||
return (
|
||||
<UpvoteView
|
||||
author={author}
|
||||
authorPayout={authorPayout}
|
||||
curationPayout={curationPayout}
|
||||
currentAccount={currentAccount}
|
||||
fetchPost={fetchPost}
|
||||
globalProps={globalProps}
|
||||
handleSetUpvotePercent={_setUpvotePercent}
|
||||
isDecinedPayout={isDecinedPayout}
|
||||
isLoggedIn={isLoggedIn}
|
||||
isShowPayoutValue={isShowPayoutValue}
|
||||
isVoted={isVoted}
|
||||
isDownVoted={isDownVoted}
|
||||
payoutDate={payoutDate}
|
||||
pendingPayout={pendingPayout}
|
||||
permlink={permlink}
|
||||
pinCode={pinCode}
|
||||
promotedPayout={promotedPayout}
|
||||
totalPayout={totalPayout}
|
||||
upvotePercent={upvotePercent}
|
||||
beneficiaries={beneficiaries}
|
||||
warnZeroPayout={warnZeroPayout}
|
||||
breakdownPayout={breakdownPayout}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<UpvoteView
|
||||
author={author}
|
||||
authorPayout={authorPayout}
|
||||
curationPayout={curationPayout}
|
||||
currentAccount={currentAccount}
|
||||
fetchPost={fetchPost}
|
||||
globalProps={globalProps}
|
||||
handleSetUpvotePercent={_setUpvotePercent}
|
||||
isDecinedPayout={isDecinedPayout}
|
||||
isLoggedIn={isLoggedIn}
|
||||
isShowPayoutValue={isShowPayoutValue}
|
||||
isVoted={isVoted}
|
||||
isDownVoted={isDownVoted}
|
||||
payoutDate={payoutDate}
|
||||
pendingPayout={pendingPayout}
|
||||
permlink={permlink}
|
||||
pinCode={pinCode}
|
||||
promotedPayout={promotedPayout}
|
||||
totalPayout={totalPayout}
|
||||
upvotePercent={upvotePercent}
|
||||
beneficiaries={beneficiaries}
|
||||
warnZeroPayout={warnZeroPayout}
|
||||
breakdownPayout={breakdownPayout}
|
||||
/>
|
||||
);
|
||||
// Component Life Cycle Functions
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Component Life Cycle Functions
|
||||
|
||||
// Component Functions
|
||||
// Component Functions
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
isLoggedIn: state.application.isLoggedIn,
|
||||
|
Loading…
Reference in New Issue
Block a user