From ae986339d58f71506895cd8f44f28db0dc0e00ba Mon Sep 17 00:00:00 2001 From: u-e Date: Wed, 24 Jul 2019 15:45:01 +0300 Subject: [PATCH 1/4] updated promote screen --- .../posts/container/postsContainer.js | 18 ++++++++++- src/containers/pointsContainer.js | 2 +- src/providers/esteem/esteem.js | 2 ++ src/screens/promote/screen/promoteScreen.js | 30 ++++++++++++------- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/components/posts/container/postsContainer.js b/src/components/posts/container/postsContainer.js index 51523c630..821a28ecc 100644 --- a/src/components/posts/container/postsContainer.js +++ b/src/components/posts/container/postsContainer.js @@ -9,6 +9,7 @@ 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 @@ -18,13 +19,26 @@ import { setFeedPosts } from '../../../redux/actions/postsAction'; class PostsContainer extends PureComponent { constructor(props) { super(props); - this.state = {}; + this.state = { + promotePosts: [], + }; } // 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; @@ -41,6 +55,7 @@ class PostsContainer extends PureComponent { render() { const { currentAccount, isLoginDone, tag, feedPosts, isConnected } = this.props; + const { promotePosts } = this.state; if (!isLoginDone && !tag) { return ( @@ -53,6 +68,7 @@ class PostsContainer extends PureComponent { return ( ({ isConnected: state.application.isConnected, accounts: state.account.otherAccounts, currentAccount: state.account.currentAccount, - pinCode: state.account.pin, + pinCode: state.application.pin, isPinCodeOpen: state.application.isPinCodeOpen, }); diff --git a/src/providers/esteem/esteem.js b/src/providers/esteem/esteem.js index 9f2f9bebc..0872ca7e1 100644 --- a/src/providers/esteem/esteem.js +++ b/src/providers/esteem/esteem.js @@ -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); diff --git a/src/screens/promote/screen/promoteScreen.js b/src/screens/promote/screen/promoteScreen.js index 3628dfdb6..7793f4f1a 100644 --- a/src/screens/promote/screen/promoteScreen.js +++ b/src/screens/promote/screen/promoteScreen.js @@ -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}; @@ -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, From ae6f49dac6b776e84773b4984d1c9a1a42b42711 Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Wed, 24 Jul 2019 19:07:25 +0300 Subject: [PATCH 2/4] Fixed profile feed issue --- src/components/posts/view/postsView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/posts/view/postsView.js b/src/components/posts/view/postsView.js index cc9a61b8e..218526678 100644 --- a/src/components/posts/view/postsView.js +++ b/src/components/posts/view/postsView.js @@ -76,7 +76,7 @@ class PostsView extends Component { isLoading: false, isPostsLoading: false, isHideImage: false, - selectedFilterIndex: 1, + selectedFilterIndex: get(nextProps, 'selectedOptionIndex', 0), isNoPost: false, }, () => { From 9b41819da4a61ec376c65484ebdbaffeabeb0261 Mon Sep 17 00:00:00 2001 From: u-e Date: Wed, 24 Jul 2019 23:58:31 +0300 Subject: [PATCH 3/4] added promote posts endpoint --- .../posts/container/postsContainer.js | 18 ++------ src/components/posts/view/postsView.js | 42 +++++++++++++++++-- src/config/api.js | 1 + src/config/ePoint.js | 11 ----- src/providers/esteem/ePoint.js | 2 +- 5 files changed, 44 insertions(+), 30 deletions(-) delete mode 100644 src/config/ePoint.js diff --git a/src/components/posts/container/postsContainer.js b/src/components/posts/container/postsContainer.js index 821a28ecc..10247ce05 100644 --- a/src/components/posts/container/postsContainer.js +++ b/src/components/posts/container/postsContainer.js @@ -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 ( { + 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); } diff --git a/src/config/api.js b/src/config/api.js index 704e22742..8a8ddbf80 100644 --- a/src/config/api.js +++ b/src/config/api.js @@ -5,6 +5,7 @@ const api = axios.create({ baseURL: Config.BACKEND_URL, headers: { 'Content-Type': 'application/json', + 'User-Agent': Config.USER_AGENT, }, }); diff --git a/src/config/ePoint.js b/src/config/ePoint.js deleted file mode 100644 index a180ed5a2..000000000 --- a/src/config/ePoint.js +++ /dev/null @@ -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; diff --git a/src/providers/esteem/ePoint.js b/src/providers/esteem/ePoint.js index 33c6ca677..aa3e9ca70 100644 --- a/src/providers/esteem/ePoint.js +++ b/src/providers/esteem/ePoint.js @@ -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 => { From 9f1ed6e2fb5bbe500e285aa86fce6b9ede5d817b Mon Sep 17 00:00:00 2001 From: u-e Date: Wed, 24 Jul 2019 23:59:03 +0300 Subject: [PATCH 4/4] updated missing part --- src/components/posts/view/postsView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/posts/view/postsView.js b/src/components/posts/view/postsView.js index f263eb025..96d24a8c6 100644 --- a/src/components/posts/view/postsView.js +++ b/src/components/posts/view/postsView.js @@ -212,7 +212,7 @@ class PostsView extends Component { // } // } // }); - _posts = promotedPosts; + // _posts = promotedPosts; if (posts.length < 5) { setFeedPosts(_posts);