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

This commit is contained in:
Mustafa Buyukcelebi 2019-07-25 15:13:23 +03:00
commit 95c20818bb
8 changed files with 70 additions and 28 deletions

View File

@ -18,7 +18,9 @@ import { setFeedPosts } from '../../../redux/actions/postsAction';
class PostsContainer extends PureComponent {
constructor(props) {
super(props);
this.state = {};
this.state = {
promotedPosts: [],
};
}
// Component Life Cycle Functions
@ -41,6 +43,7 @@ class PostsContainer extends PureComponent {
render() {
const { currentAccount, isLoginDone, tag, feedPosts, isConnected } = this.props;
const { promotedPosts } = this.state;
if (!isLoginDone && !tag) {
return (
@ -53,6 +56,7 @@ class PostsContainer extends PureComponent {
return (
<PostsView
promotedPosts={promotedPosts}
handleOnScrollStart={this._handleOnScrollStart}
currentAccountUsername={
currentAccount && (get(currentAccount, 'username') || get(currentAccount, 'name'))

View File

@ -1,3 +1,5 @@
/* eslint-disable no-unused-expressions */
/* eslint-disable array-callback-return */
import React, { Component, Fragment } from 'react';
import { FlatList, View, ActivityIndicator, RefreshControl } from 'react-native';
import { injectIntl } from 'react-intl';
@ -5,7 +7,8 @@ import { withNavigation } from 'react-navigation';
import get from 'lodash/get';
// STEEM
import { getPostsSummary } from '../../../providers/steem/dsteem';
import { getPostsSummary, getPost } from '../../../providers/steem/dsteem';
import { getPromotePosts } from '../../../providers/esteem/esteem';
// COMPONENTS
import { PostCard } from '../../postCard';
@ -31,6 +34,7 @@ class PostsView extends Component {
isHideImage: false,
selectedFilterIndex: get(props, 'selectedOptionIndex', 0),
isNoPost: false,
promotedPosts: [],
};
}
@ -43,10 +47,11 @@ class PostsView extends Component {
});
}
componentDidMount() {
async componentDidMount() {
const { isConnected } = this.props;
if (isConnected) {
await this._getPromotePosts();
this._loadPosts();
} else {
this.setState({
@ -76,7 +81,7 @@ class PostsView extends Component {
isLoading: false,
isPostsLoading: false,
isHideImage: false,
selectedFilterIndex: 1,
selectedFilterIndex: get(nextProps, 'selectedOptionIndex', 0),
isNoPost: false,
},
() => {
@ -89,11 +94,26 @@ class PostsView extends Component {
}
}
_getPromotePosts = async () => {
const { currentAccountUsername } = this.props;
await getPromotePosts().then(async res => {
const promotedPosts = [];
res &&
res.length > 0 &&
res.map(async item => {
const post = await getPost(item.author, item.permlink, currentAccountUsername);
promotedPosts.push(post);
});
await this.setState({ promotedPosts });
});
};
_scrollToTop = () => {
if (this.flatList) this.flatList.scrollToOffset({ x: 0, y: 0, animated: true });
};
_loadPosts = () => {
_loadPosts = async () => {
const {
getFor,
tag,
@ -110,6 +130,7 @@ class PostsView extends Component {
refreshing,
selectedFilterIndex,
isLoading,
promotedPosts,
} = this.state;
const filter =
pageType === 'posts'
@ -157,6 +178,7 @@ class PostsView extends Component {
.then(result => {
if (result.length > 0) {
let _posts = result;
console.log(promotedPosts);
if (filter === 'reblogs') {
for (let i = _posts.length - 1; i >= 0; i--) {
@ -178,6 +200,20 @@ 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);
}

View File

@ -5,6 +5,7 @@ const api = axios.create({
baseURL: Config.BACKEND_URL,
headers: {
'Content-Type': 'application/json',
'User-Agent': Config.USER_AGENT,
},
});

View File

@ -1,11 +0,0 @@
import axios from 'axios';
import Config from 'react-native-config';
const ePoint = axios.create({
baseURL: Config.BACKEND_URL,
headers: {
'User-Agent': Config.USER_AGENT,
},
});
export default ePoint;

View File

@ -257,7 +257,7 @@ const mapStateToProps = state => ({
isConnected: state.application.isConnected,
accounts: state.account.otherAccounts,
currentAccount: state.account.currentAccount,
pinCode: state.account.pin,
pinCode: state.application.pin,
isPinCodeOpen: state.application.isPinCodeOpen,
});

View File

@ -1,5 +1,5 @@
import { Alert } from 'react-native';
import ePointApi from '../../config/ePoint';
import ePointApi from '../../config/api';
export const userActivity = (us, ty, bl = '', tx = '') =>
new Promise(resolve => {

View File

@ -309,3 +309,5 @@ export const getSCAccessToken = code =>
new Promise(resolve => {
api.post('/sc-token-refresh', { code }).then(resp => resolve(resp.data));
});
export const getPromotePosts = () => api.get(`/promoted-posts`).then(resp => resp.data);

View File

@ -53,17 +53,28 @@ class PointsScreen extends PureComponent {
// Component Functions
_handleOnPermlinkChange = async text => {
this.setState({ permlink: text, isValid: false });
if (this.timer) {
clearTimeout(this.timer);
}
if (text.trim().length < 3) {
this.setState({ permlinkSuggestions: [] });
return;
}
if (text && text.length > 0) {
searchPath(text).then(res => {
this.setState({ permlinkSuggestions: res && res.length > 10 ? res.slice(0, 7) : res });
});
this.timer = setTimeout(
() =>
searchPath(text).then(res => {
this.setState({ permlinkSuggestions: res && res.length > 10 ? res.slice(0, 7) : res });
}),
500,
);
} else {
await this.setState({ permlinkSuggestions: [], isValid: false });
}
// if (!text || (text && text.length < 1))
this.setState({ permlink: text, isValid: false });
};
_renderDescription = text => <Text style={styles.description}>{text}</Text>;
@ -99,14 +110,13 @@ class PointsScreen extends PureComponent {
_promote = async (promote, currentAccount, getUserDataWithUsername, navigationParams) => {
const { day, permlink, selectedUser } = this.state;
const fullPermlink = permlink || get(navigationParams, 'permlink');
const seperatedPermlink = permlink ? permlink.split('/') : get(navigationParams, 'permlink');
const seperatedPermlink = fullPermlink.split('/');
const _author = get(seperatedPermlink, '[0]');
const _permlink = get(seperatedPermlink, '[1]');
if (get(currentAccount, 'local.authType') === 'steemConnect') {
// const user = selectedUser;
const json = JSON.stringify({
user: selectedUser,
_author,