From e3a346791d4c56290160ad77f787d74820793509 Mon Sep 17 00:00:00 2001 From: feruz Date: Mon, 13 Jan 2020 13:12:40 +0200 Subject: [PATCH] WIP: get more replies and comments on profile page --- src/components/profile/profileView.js | 24 ++++++++++++++++++++++-- src/containers/profileContainer.js | 12 ++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/components/profile/profileView.js b/src/components/profile/profileView.js index 53b7af1c7..2d5e25e91 100644 --- a/src/components/profile/profileView.js +++ b/src/components/profile/profileView.js @@ -43,6 +43,17 @@ class ProfileView extends PureComponent { } }; + _loadMoreComments = () => { + const { getReplies, comments } = this.props; + + if (comments && comments.length > 0) { + getReplies({ + author: comments[comments.length - 1].author, + permlink: comments[comments.length - 1].permlink, + }); + } + }; + _handleOnSummaryExpanded = () => { const { isSummaryOpen } = this.state; @@ -55,6 +66,10 @@ class ProfileView extends PureComponent { this.setState({ collapsibleMoreHeight: height }); }; + _isCloseToBottom({ layoutMeasurement, contentOffset, contentSize }) { + return layoutMeasurement.height + contentOffset.y >= contentSize.height - 20; + } + render() { const { about, @@ -198,9 +213,14 @@ class ProfileView extends PureComponent { > {comments && comments.length > 0 ? ( { + this._handleOnScroll(); + if (this._isCloseToBottom(nativeEvent)) { + this._loadMoreComments(); + } + }} contentContainerStyle={styles.scrollContentContainer} - scrollEventThrottle={16} + //scrollEventThrottle={16} > { + _getReplies = async query => { const { isOwnProfile } = this.state; let repliesAction; @@ -86,7 +86,11 @@ class ProfileContainer extends Component { repliesAction = getRepliesByLastUpdate; } - await repliesAction({ start_author: user, limit: 10 }).then(result => { + await repliesAction({ + start_author: query.author, + start_permlink: query.permlink, + limit: 10, + }).then(result => { this.setState({ comments: result, }); @@ -229,7 +233,7 @@ class ProfileContainer extends Component { username, })); - this._getReplies(username); + this._getReplies({ author: username, permlink: undefined }); }; _handleFollowsPress = async isFollowingPress => { @@ -364,7 +368,7 @@ class ProfileContainer extends Component { error, follows, forceLoadPost, - getReplies: () => this._getReplies(username), + getReplies: this._getReplies, handleFollowUnfollowUser: this._handleFollowUnfollowUser, handleMuteUnmuteUser: this._handleMuteUnmuteUser, handleOnBackPress: this._handleOnBackPress,