diff --git a/src/components/postCard/view/postCardView.js b/src/components/postCard/view/postCardView.js index 5d719cfba..2f80967ac 100644 --- a/src/components/postCard/view/postCardView.js +++ b/src/components/postCard/view/postCardView.js @@ -1,4 +1,5 @@ import React, { Component } from 'react'; +import get from 'lodash/get'; import { TouchableOpacity, Text, View } from 'react-native'; import FastImage from 'react-native-fast-image'; import { injectIntl } from 'react-intl'; @@ -71,22 +72,24 @@ class PostCardView extends Component { const { content, isHideImage, fetchPost, isNsfwPost, isHideReblogOption } = this.props; const _image = this._getPostImage(content, isNsfwPost); - const reblogedBy = content.reblogged_by && content.reblogged_by[0]; + const reblogedBy = get(content, 'reblogged_by') && content.reblogged_by[0]; return ( + {/* {get(content, 'is_promoted') && 'promoted'} */} - {content.vote_count} + {get(content, 'vote_count', 0)} - {content.children} + {get(content, 'children')} diff --git a/src/components/postElements/headerDescription/view/postHeaderDescription.js b/src/components/postElements/headerDescription/view/postHeaderDescription.js index 46b379f08..8838dff11 100644 --- a/src/components/postElements/headerDescription/view/postHeaderDescription.js +++ b/src/components/postElements/headerDescription/view/postHeaderDescription.js @@ -1,4 +1,4 @@ -import React, { PureComponent } from 'react'; +import React, { PureComponent, Fragment } from 'react'; import { View, Text, TouchableOpacity } from 'react-native'; import { withNavigation } from 'react-navigation'; @@ -61,42 +61,56 @@ class PostHeaderDescription extends PureComponent { tag, tagOnPress, isShowOwnerIndicator, + isPromoted, } = this.props; const { reblogedBy } = this.state; const _reputationText = `(${reputation})`; return ( - - this._handleOnUserPress(name)} - > - {!isHideImage && ( - + + this._handleOnUserPress(name)} + > + {!isHideImage && ( + + )} + {name} + {_reputationText} + + {!!tag && ( + tagOnPress && tagOnPress()}> + + + )} + {date} + {isShowOwnerIndicator && ( + + )} + {/* {!!reblogedBy && ( + // + + )} */} + + + {!!reblogedBy && ( + )} - {name} - {_reputationText} - - {!!tag && ( - tagOnPress && tagOnPress()}> - - - )} - {date} - {isShowOwnerIndicator && ( - - )} - {!!reblogedBy && ( - // - - )} + {/* {isPromoted && sponsored} */} + {isPromoted && sponsored} + ); } diff --git a/src/components/postElements/headerDescription/view/postHeaderDescriptionStyles.js b/src/components/postElements/headerDescription/view/postHeaderDescriptionStyles.js index ccda02672..e68a1c6ac 100644 --- a/src/components/postElements/headerDescription/view/postHeaderDescriptionStyles.js +++ b/src/components/postElements/headerDescription/view/postHeaderDescriptionStyles.js @@ -5,6 +5,24 @@ export default EStyleSheet.create({ flexDirection: 'row', alignItems: 'center', }, + subLine: { + marginTop: 5, + marginHorizontal: 3, + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'space-between', + width: '$deviceWidth - 30', + flex: 1, + }, + sponsoredText: { + fontSize: 10, + color: '$primaryDarkGray', + // alignItems: 'flex-end', + // alignItems: 'flex-end', + // justifyContent: 'flex-end', + // alignItems: 'center', + alignSelf: 'flex-end', + }, avatar: { borderColor: '$borderColor', borderWidth: 1, diff --git a/src/components/posts/view/postsView.js b/src/components/posts/view/postsView.js index 96d24a8c6..18f309454 100644 --- a/src/components/posts/view/postsView.js +++ b/src/components/posts/view/postsView.js @@ -101,7 +101,7 @@ class PostsView extends Component { res && res.length > 0 && res.map(async item => { - const post = await getPost(item.author, item.permlink, currentAccountUsername); + const post = await getPost(item.author, item.permlink, currentAccountUsername, true); promotedPosts.push(post); }); @@ -138,6 +138,7 @@ class PostsView extends Component { : PROFILE_FILTERS[selectedFilterIndex].toLowerCase(); let options; let newPosts = []; + const limit = promotedPosts ? (promotedPosts.length >= 3 ? 9 : 6) : 3; if (!isConnected) { this.setState({ @@ -156,16 +157,16 @@ class PostsView extends Component { if (tag || filter === 'feed' || filter === 'blog' || getFor === 'blog') { options = { tag, - limit: 3, + limit, }; } else if (filter === 'reblogs') { options = { tag, - limit: 3, + limit, }; } else { options = { - limit: 3, + limit, }; } @@ -200,20 +201,6 @@ class PostsView extends Component { } } - // result && - // result.length > 0 && - // result.map((item, i) => { - // if ([3, 6, 9].includes(i)) { - // const ix = i / 3 - 1; - // if (promotedPosts[ix] !== undefined) { - // const p = promotedPosts[ix]; - - // _posts.push(p); - // } - // } - // }); - // _posts = promotedPosts; - if (posts.length < 5) { setFeedPosts(_posts); } @@ -223,6 +210,12 @@ class PostsView extends Component { posts: _posts, }); } else if (!refreshing) { + if (!startAuthor) { + promotedPosts.map((promotedItem, i) => { + _posts.splice((i + 1) * 3, i * 3, promotedItem); + }); + } + this.setState({ posts: _posts, startAuthor: result[result.length - 1] && result[result.length - 1].author, diff --git a/src/providers/steem/dsteem.js b/src/providers/steem/dsteem.js index 1e18b920c..a69392645 100644 --- a/src/providers/steem/dsteem.js +++ b/src/providers/steem/dsteem.js @@ -349,11 +349,11 @@ export const getRepliesByLastUpdate = async query => { * @param permlink post permlink * @param currentUserName active accounts username */ -export const getPost = async (author, permlink, currentUserName = null) => { +export const getPost = async (author, permlink, currentUserName = null, isPromoted = false) => { try { const post = await client.database.call('get_content', [author, permlink]); - return post ? await parsePost(post, currentUserName) : null; + return post ? await parsePost(post, currentUserName, isPromoted) : null; } catch (error) { return error; } diff --git a/src/utils/postParser.js b/src/utils/postParser.js index 234cab5ca..28124cded 100644 --- a/src/utils/postParser.js +++ b/src/utils/postParser.js @@ -13,7 +13,7 @@ import { getReputation } from './reputation'; export const parsePosts = (posts, currentUserName) => !posts ? null : posts.map(post => parsePost(post, currentUserName)); -export const parsePost = (post, currentUserName) => { +export const parsePost = (post, currentUserName, isPromoted) => { if (!post) { return null; } @@ -21,7 +21,7 @@ export const parsePost = (post, currentUserName) => { if (currentUserName === post.author) { post.markdownBody = post.body; } - + post.is_promoted = isPromoted; post.json_metadata = JSON.parse(post.json_metadata); post.image = postImage(post.json_metadata, post.body); post.vote_count = post.active_votes.length;