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 240e6d4d37
6 changed files with 85 additions and 57 deletions

View File

@ -1,4 +1,5 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import get from 'lodash/get';
import { TouchableOpacity, Text, View } from 'react-native'; import { TouchableOpacity, Text, View } from 'react-native';
import FastImage from 'react-native-fast-image'; import FastImage from 'react-native-fast-image';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
@ -71,22 +72,24 @@ class PostCardView extends Component {
const { content, isHideImage, fetchPost, isNsfwPost, isHideReblogOption } = this.props; const { content, isHideImage, fetchPost, isNsfwPost, isHideReblogOption } = this.props;
const _image = this._getPostImage(content, isNsfwPost); 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 ( return (
<View style={styles.post}> <View style={styles.post}>
<View style={styles.bodyHeader}> <View style={styles.bodyHeader}>
<PostHeaderDescription <PostHeaderDescription
// date={intl.formatRelative(content.created)} // date={intl.formatRelative(content.created)}
date={getTimeFromNow(content.created)} date={getTimeFromNow(get(content, 'created'))}
isHideImage={isHideImage} isHideImage={isHideImage}
name={content.author} name={get(content, 'author')}
profileOnPress={this._handleOnUserPress} profileOnPress={this._handleOnUserPress}
reputation={content.author_reputation} reputation={get(content, 'author_reputation')}
size={32} size={32}
tag={content.category} tag={content.category}
reblogedBy={reblogedBy} reblogedBy={reblogedBy}
isPromoted={get(content, 'is_promoted')}
/> />
{/* <Text>{get(content, 'is_promoted') && 'promoted'}</Text> */}
<View style={styles.dropdownWrapper}> <View style={styles.dropdownWrapper}>
<PostDropdown <PostDropdown
isHideReblogOption={isHideReblogOption} isHideReblogOption={isHideReblogOption}
@ -121,12 +124,12 @@ class PostCardView extends Component {
iconType="MaterialIcons" iconType="MaterialIcons"
name="people" name="people"
/> />
<Text style={styles.comment}>{content.vote_count}</Text> <Text style={styles.comment}>{get(content, 'vote_count', 0)}</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
<View style={styles.commentButton}> <View style={styles.commentButton}>
<Icon style={[styles.commentIcon]} iconType="MaterialIcons" name="comment" /> <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>
</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 { View, Text, TouchableOpacity } from 'react-native';
import { withNavigation } from 'react-navigation'; import { withNavigation } from 'react-navigation';
@ -61,42 +61,56 @@ class PostHeaderDescription extends PureComponent {
tag, tag,
tagOnPress, tagOnPress,
isShowOwnerIndicator, isShowOwnerIndicator,
isPromoted,
} = this.props; } = this.props;
const { reblogedBy } = this.state; const { reblogedBy } = this.state;
const _reputationText = `(${reputation})`; const _reputationText = `(${reputation})`;
return ( return (
<View style={styles.container}> <View>
<TouchableOpacity <View style={styles.container}>
style={styles.avatarNameWrapper} <TouchableOpacity
onPress={() => this._handleOnUserPress(name)} style={styles.avatarNameWrapper}
> onPress={() => this._handleOnUserPress(name)}
{!isHideImage && ( >
<UserAvatar {!isHideImage && (
style={[styles.avatar, { width: size, height: size, borderRadius: size / 2 }]} <UserAvatar
disableSize style={[styles.avatar, { width: size, height: size, borderRadius: size / 2 }]}
username={name} disableSize
defaultSource={DEFAULT_IMAGE} username={name}
noAction 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> {/* {isPromoted && <Text>sponsored</Text>} */}
<Text style={styles.reputation}>{_reputationText}</Text> {isPromoted && <Text style={styles.sponsoredText}>sponsored</Text>}
</TouchableOpacity> </View>
{!!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>
); );
} }

View File

@ -5,6 +5,24 @@ export default EStyleSheet.create({
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', 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: { avatar: {
borderColor: '$borderColor', borderColor: '$borderColor',
borderWidth: 1, borderWidth: 1,

View File

@ -101,7 +101,7 @@ class PostsView extends Component {
res && res &&
res.length > 0 && res.length > 0 &&
res.map(async item => { 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); promotedPosts.push(post);
}); });
@ -138,6 +138,7 @@ class PostsView extends Component {
: PROFILE_FILTERS[selectedFilterIndex].toLowerCase(); : PROFILE_FILTERS[selectedFilterIndex].toLowerCase();
let options; let options;
let newPosts = []; let newPosts = [];
const limit = promotedPosts ? (promotedPosts.length >= 3 ? 9 : 6) : 3;
if (!isConnected) { if (!isConnected) {
this.setState({ this.setState({
@ -156,16 +157,16 @@ class PostsView extends Component {
if (tag || filter === 'feed' || filter === 'blog' || getFor === 'blog') { if (tag || filter === 'feed' || filter === 'blog' || getFor === 'blog') {
options = { options = {
tag, tag,
limit: 3, limit,
}; };
} else if (filter === 'reblogs') { } else if (filter === 'reblogs') {
options = { options = {
tag, tag,
limit: 3, limit,
}; };
} else { } else {
options = { 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) { if (posts.length < 5) {
setFeedPosts(_posts); setFeedPosts(_posts);
} }
@ -223,6 +210,12 @@ class PostsView extends Component {
posts: _posts, posts: _posts,
}); });
} else if (!refreshing) { } else if (!refreshing) {
if (!startAuthor) {
promotedPosts.map((promotedItem, i) => {
_posts.splice((i + 1) * 3, i * 3, promotedItem);
});
}
this.setState({ this.setState({
posts: _posts, posts: _posts,
startAuthor: result[result.length - 1] && result[result.length - 1].author, 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 permlink post permlink
* @param currentUserName active accounts username * @param currentUserName active accounts username
*/ */
export const getPost = async (author, permlink, currentUserName = null) => { export const getPost = async (author, permlink, currentUserName = null, isPromoted = false) => {
try { try {
const post = await client.database.call('get_content', [author, permlink]); 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) { } catch (error) {
return error; return error;
} }

View File

@ -13,7 +13,7 @@ import { getReputation } from './reputation';
export const parsePosts = (posts, currentUserName) => export const parsePosts = (posts, currentUserName) =>
!posts ? null : posts.map(post => parsePost(post, currentUserName)); !posts ? null : posts.map(post => parsePost(post, currentUserName));
export const parsePost = (post, currentUserName) => { export const parsePost = (post, currentUserName, isPromoted) => {
if (!post) { if (!post) {
return null; return null;
} }
@ -21,7 +21,7 @@ export const parsePost = (post, currentUserName) => {
if (currentUserName === post.author) { if (currentUserName === post.author) {
post.markdownBody = post.body; post.markdownBody = post.body;
} }
post.is_promoted = isPromoted;
post.json_metadata = JSON.parse(post.json_metadata); post.json_metadata = JSON.parse(post.json_metadata);
post.image = postImage(post.json_metadata, post.body); post.image = postImage(post.json_metadata, post.body);
post.vote_count = post.active_votes.length; post.vote_count = post.active_votes.length;