added promote posts endpoint

This commit is contained in:
u-e 2019-07-24 23:58:31 +03:00
parent dc41c25ba3
commit 9b41819da4
5 changed files with 44 additions and 30 deletions

View File

@ -9,7 +9,6 @@ import { PostCardPlaceHolder } from '../../basicUIElements';
// Actions
import { isCollapsePostButton } from '../../../redux/actions/uiAction';
import { setFeedPosts } from '../../../redux/actions/postsAction';
import { getPromotePosts } from '../../../providers/esteem/esteem';
/*
* Props Name Description Value
*@props --> props name here description here Value Type Here
@ -20,25 +19,14 @@ class PostsContainer extends PureComponent {
constructor(props) {
super(props);
this.state = {
promotePosts: [],
promotedPosts: [],
};
}
// Component Life Cycle Functions
componentDidMount() {
this._getPromotePosts();
}
// Component Functions
_getPromotePosts = () => {
getPromotePosts().then(res => {
this.setState({ promotePosts: res });
console.log(res);
});
};
_handleOnScrollStart = () => {
const { dispatch, isCollapsePostButtonOpen } = this.props;
@ -55,7 +43,7 @@ class PostsContainer extends PureComponent {
render() {
const { currentAccount, isLoginDone, tag, feedPosts, isConnected } = this.props;
const { promotePosts } = this.state;
const { promotedPosts } = this.state;
if (!isLoginDone && !tag) {
return (
@ -68,7 +56,7 @@ class PostsContainer extends PureComponent {
return (
<PostsView
promotePosts={promotePosts}
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({
@ -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

@ -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 => {