improve posts parsing

This commit is contained in:
feruz 2021-02-04 19:37:14 +02:00
parent 352cff75b1
commit 911ea6c77b
4 changed files with 38 additions and 13 deletions

View File

@ -39,14 +39,31 @@ const PostCardContainer = ({
}, [isRefresh]); }, [isRefresh]);
useEffect(() => { useEffect(() => {
let isCancelled = false;
const fetchData = async (val) => {
try {
const dd = await getPostReblogs(val);
if (!isCancelled) {
setReblogs(dd);
return dd;
}
} catch (e) {
if (!isCancelled) {
setReblogs([]);
return val;
}
}
};
if (_content) { if (_content) {
setActiveVotes(get(_content, 'active_votes', [])); setActiveVotes(get(_content, 'active_votes', []));
getPostReblogs(_content).then((result) => {
setReblogs(result);
});
setContent(_content); setContent(_content);
fetchData(_content);
} }
return () => {
isCancelled = true;
};
}, [_content]); }, [_content]);
const _handleOnUserPress = () => { const _handleOnUserPress = () => {

View File

@ -85,8 +85,8 @@ const PostsContainer = ({
useEffect(() => { useEffect(() => {
if (isConnected) { if (isConnected) {
_getPromotePosts();
_loadPosts(); _loadPosts();
_getPromotePosts();
} }
}, [ }, [
_getPromotePosts, _getPromotePosts,

View File

@ -417,7 +417,7 @@ export const getSCAccessToken = (code) =>
export const getPromotePosts = () => { export const getPromotePosts = () => {
try { try {
return api.get('/promoted-posts?limit=50').then((resp) => resp.data); return api.get('/promoted-posts?limit=10').then((resp) => resp.data);
} catch (error) { } catch (error) {
return error; return error;
} }

View File

@ -7,7 +7,7 @@ import { postBodySummary, renderPostBody, catchPostImage } from '@ecency/render-
// Utils // Utils
import parseAsset from './parseAsset'; import parseAsset from './parseAsset';
import { getReputation } from './reputation'; import { getReputation } from './reputation';
import { getResizedAvatar } from './image'; import { getResizedAvatar, getResizedImage } from './image';
const webp = Platform.OS === 'ios' ? false : true; const webp = Platform.OS === 'ios' ? false : true;
@ -27,13 +27,21 @@ export const parsePost = (post, currentUserName, isPromoted, isList = false) =>
post.markdownBody = post.body; post.markdownBody = post.body;
} }
post.is_promoted = isPromoted; post.is_promoted = isPromoted;
try { if (typeof post.json_metadata === 'string' || post.json_metadata instanceof String) {
post.json_metadata = JSON.parse(post.json_metadata); try {
} catch (error) { post.json_metadata = JSON.parse(post.json_metadata);
post.json_metadata = {}; } catch (error) {
post.json_metadata = {};
}
}
if (post.json_metadata && post.json_metadata.image) {
const [imageLink] = post.json_metadata.image;
post.thumbnail = getResizedImage(imageLink, 10);
post.image = getResizedImage(imageLink, 600);
} else {
post.image = catchPostImage(post.body, 600, 500, webp ? 'webp' : 'match');
post.thumbnail = catchPostImage(post.body, 10, 7, webp ? 'webp' : 'match');
} }
post.image = catchPostImage(post.body, 600, 500, webp ? 'webp' : 'match');
post.thumbnail = catchPostImage(post.body, 10, 7, webp ? 'webp' : 'match');
post.author_reputation = getReputation(post.author_reputation); post.author_reputation = getReputation(post.author_reputation);
post.avatar = getResizedAvatar(get(post, 'author')); post.avatar = getResizedAvatar(get(post, 'author'));
if (!isList) { if (!isList) {