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 // Actions
import { isCollapsePostButton } from '../../../redux/actions/uiAction'; import { isCollapsePostButton } from '../../../redux/actions/uiAction';
import { setFeedPosts } from '../../../redux/actions/postsAction'; import { setFeedPosts } from '../../../redux/actions/postsAction';
import { getPromotePosts } from '../../../providers/esteem/esteem';
/* /*
* Props Name Description Value * Props Name Description Value
*@props --> props name here description here Value Type Here *@props --> props name here description here Value Type Here
@ -20,25 +19,14 @@ class PostsContainer extends PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
promotePosts: [], promotedPosts: [],
}; };
} }
// Component Life Cycle Functions // Component Life Cycle Functions
componentDidMount() {
this._getPromotePosts();
}
// Component Functions // Component Functions
_getPromotePosts = () => {
getPromotePosts().then(res => {
this.setState({ promotePosts: res });
console.log(res);
});
};
_handleOnScrollStart = () => { _handleOnScrollStart = () => {
const { dispatch, isCollapsePostButtonOpen } = this.props; const { dispatch, isCollapsePostButtonOpen } = this.props;
@ -55,7 +43,7 @@ class PostsContainer extends PureComponent {
render() { render() {
const { currentAccount, isLoginDone, tag, feedPosts, isConnected } = this.props; const { currentAccount, isLoginDone, tag, feedPosts, isConnected } = this.props;
const { promotePosts } = this.state; const { promotedPosts } = this.state;
if (!isLoginDone && !tag) { if (!isLoginDone && !tag) {
return ( return (
@ -68,7 +56,7 @@ class PostsContainer extends PureComponent {
return ( return (
<PostsView <PostsView
promotePosts={promotePosts} promotedPosts={promotedPosts}
handleOnScrollStart={this._handleOnScrollStart} handleOnScrollStart={this._handleOnScrollStart}
currentAccountUsername={ currentAccountUsername={
currentAccount && (get(currentAccount, 'username') || get(currentAccount, 'name')) 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 React, { Component, Fragment } from 'react';
import { FlatList, View, ActivityIndicator, RefreshControl } from 'react-native'; import { FlatList, View, ActivityIndicator, RefreshControl } from 'react-native';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
@ -5,7 +7,8 @@ import { withNavigation } from 'react-navigation';
import get from 'lodash/get'; import get from 'lodash/get';
// STEEM // STEEM
import { getPostsSummary } from '../../../providers/steem/dsteem'; import { getPostsSummary, getPost } from '../../../providers/steem/dsteem';
import { getPromotePosts } from '../../../providers/esteem/esteem';
// COMPONENTS // COMPONENTS
import { PostCard } from '../../postCard'; import { PostCard } from '../../postCard';
@ -31,6 +34,7 @@ class PostsView extends Component {
isHideImage: false, isHideImage: false,
selectedFilterIndex: get(props, 'selectedOptionIndex', 0), selectedFilterIndex: get(props, 'selectedOptionIndex', 0),
isNoPost: false, isNoPost: false,
promotedPosts: [],
}; };
} }
@ -43,10 +47,11 @@ class PostsView extends Component {
}); });
} }
componentDidMount() { async componentDidMount() {
const { isConnected } = this.props; const { isConnected } = this.props;
if (isConnected) { if (isConnected) {
await this._getPromotePosts();
this._loadPosts(); this._loadPosts();
} else { } else {
this.setState({ 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 = () => { _scrollToTop = () => {
if (this.flatList) this.flatList.scrollToOffset({ x: 0, y: 0, animated: true }); if (this.flatList) this.flatList.scrollToOffset({ x: 0, y: 0, animated: true });
}; };
_loadPosts = () => { _loadPosts = async () => {
const { const {
getFor, getFor,
tag, tag,
@ -110,6 +130,7 @@ class PostsView extends Component {
refreshing, refreshing,
selectedFilterIndex, selectedFilterIndex,
isLoading, isLoading,
promotedPosts,
} = this.state; } = this.state;
const filter = const filter =
pageType === 'posts' pageType === 'posts'
@ -157,6 +178,7 @@ class PostsView extends Component {
.then(result => { .then(result => {
if (result.length > 0) { if (result.length > 0) {
let _posts = result; let _posts = result;
console.log(promotedPosts);
if (filter === 'reblogs') { if (filter === 'reblogs') {
for (let i = _posts.length - 1; i >= 0; i--) { 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) { if (posts.length < 5) {
setFeedPosts(_posts); setFeedPosts(_posts);
} }

View File

@ -5,6 +5,7 @@ const api = axios.create({
baseURL: Config.BACKEND_URL, baseURL: Config.BACKEND_URL,
headers: { headers: {
'Content-Type': 'application/json', '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 { Alert } from 'react-native';
import ePointApi from '../../config/ePoint'; import ePointApi from '../../config/api';
export const userActivity = (us, ty, bl = '', tx = '') => export const userActivity = (us, ty, bl = '', tx = '') =>
new Promise(resolve => { new Promise(resolve => {