mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-20 03:42:10 +03:00
improve posts parsing
This commit is contained in:
parent
352cff75b1
commit
911ea6c77b
@ -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 = () => {
|
||||||
|
@ -85,8 +85,8 @@ const PostsContainer = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
_getPromotePosts();
|
|
||||||
_loadPosts();
|
_loadPosts();
|
||||||
|
_getPromotePosts();
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
_getPromotePosts,
|
_getPromotePosts,
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user