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]);
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) {
setActiveVotes(get(_content, 'active_votes', []));
getPostReblogs(_content).then((result) => {
setReblogs(result);
});
setContent(_content);
fetchData(_content);
}
return () => {
isCancelled = true;
};
}, [_content]);
const _handleOnUserPress = () => {

View File

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

View File

@ -417,7 +417,7 @@ export const getSCAccessToken = (code) =>
export const getPromotePosts = () => {
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) {
return error;
}

View File

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