Merge branch 'feature/boost' of github.com:esteemapp/esteem-mobile into feature/boost

This commit is contained in:
Mustafa Buyukcelebi 2019-07-26 01:32:15 +03:00
commit 9c179ff960
6 changed files with 85 additions and 57 deletions

View File

@ -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 (
<View style={styles.post}>
<View style={styles.bodyHeader}>
<PostHeaderDescription
// date={intl.formatRelative(content.created)}
date={getTimeFromNow(content.created)}
date={getTimeFromNow(get(content, 'created'))}
isHideImage={isHideImage}
name={content.author}
name={get(content, 'author')}
profileOnPress={this._handleOnUserPress}
reputation={content.author_reputation}
reputation={get(content, 'author_reputation')}
size={32}
tag={content.category}
reblogedBy={reblogedBy}
isPromoted={get(content, 'is_promoted')}
/>
{/* <Text>{get(content, 'is_promoted') && 'promoted'}</Text> */}
<View style={styles.dropdownWrapper}>
<PostDropdown
isHideReblogOption={isHideReblogOption}
@ -121,12 +124,12 @@ class PostCardView extends Component {
iconType="MaterialIcons"
name="people"
/>
<Text style={styles.comment}>{content.vote_count}</Text>
<Text style={styles.comment}>{get(content, 'vote_count', 0)}</Text>
</TouchableOpacity>
</View>
<View style={styles.commentButton}>
<Icon style={[styles.commentIcon]} iconType="MaterialIcons" name="comment" />
<Text style={styles.comment}>{content.children}</Text>
<Text style={styles.comment}>{get(content, 'children')}</Text>
</View>
</View>
</View>

View File

@ -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 (
<View style={styles.container}>
<TouchableOpacity
style={styles.avatarNameWrapper}
onPress={() => this._handleOnUserPress(name)}
>
{!isHideImage && (
<UserAvatar
style={[styles.avatar, { width: size, height: size, borderRadius: size / 2 }]}
disableSize
username={name}
defaultSource={DEFAULT_IMAGE}
noAction
<View>
<View style={styles.container}>
<TouchableOpacity
style={styles.avatarNameWrapper}
onPress={() => this._handleOnUserPress(name)}
>
{!isHideImage && (
<UserAvatar
style={[styles.avatar, { width: size, height: size, borderRadius: size / 2 }]}
disableSize
username={name}
defaultSource={DEFAULT_IMAGE}
noAction
/>
)}
<Text style={styles.name}>{name}</Text>
<Text style={styles.reputation}>{_reputationText}</Text>
</TouchableOpacity>
{!!tag && (
<TouchableOpacity onPress={() => tagOnPress && tagOnPress()}>
<Tag isPostCardTag isPin value={tag} />
</TouchableOpacity>
)}
<Text style={styles.date}>{date}</Text>
{isShowOwnerIndicator && (
<Icon style={styles.ownerIndicator} name="stars" iconType="MaterialIcons" />
)}
{/* {!!reblogedBy && (
// <TextWithIcon text={reblogedBy} iconType="MaterialIcons" iconName="repeat" />
<Icon style={styles.reblogedIcon} name="repeat" iconType="MaterialIcons" />
)} */}
</View>
<View style={styles.subLine}>
{!!reblogedBy && (
<TextWithIcon
text={`rebloged by ${reblogedBy}`}
iconType="MaterialIcons"
iconName="repeat"
/>
)}
<Text style={styles.name}>{name}</Text>
<Text style={styles.reputation}>{_reputationText}</Text>
</TouchableOpacity>
{!!tag && (
<TouchableOpacity onPress={() => tagOnPress && tagOnPress()}>
<Tag isPostCardTag isPin value={tag} />
</TouchableOpacity>
)}
<Text style={styles.date}>{date}</Text>
{isShowOwnerIndicator && (
<Icon style={styles.ownerIndicator} name="stars" iconType="MaterialIcons" />
)}
{!!reblogedBy && (
// <TextWithIcon text={reblogedBy} iconType="MaterialIcons" iconName="repeat" />
<Icon style={styles.reblogedIcon} name="repeat" iconType="MaterialIcons" />
)}
{/* {isPromoted && <Text>sponsored</Text>} */}
{isPromoted && <Text style={styles.sponsoredText}>sponsored</Text>}
</View>
</View>
);
}

View File

@ -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,

View File

@ -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,

View File

@ -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;
}

View File

@ -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;