diff --git a/package.json b/package.json index d065eaee1..003adfc8a 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ }, "dependencies": { "@babel/runtime": "^7.5.5", - "@esteemapp/esteem-render-helpers": "^1.3.0", + "@esteemapp/esteem-render-helpers": "^1.3.3", "@esteemapp/react-native-autocomplete-input": "^4.2.1", "@esteemapp/react-native-multi-slider": "^1.1.0", "@esteemapp/react-native-render-html": "^4.1.5", diff --git a/src/components/postElements/body/view/config.js b/src/components/postElements/body/view/config.js index c438574a7..7131d7979 100644 --- a/src/components/postElements/body/view/config.js +++ b/src/components/postElements/body/view/config.js @@ -7,7 +7,6 @@ for (i = 0; i < images.length; i++) { } var resultStr = JSON.stringify(JSON.stringify(result)); // workaround var message = 'window.ReactNativeWebView.postMessage(' + resultStr + ')'; - images[i].setAttribute("onClick", message); } diff --git a/src/components/posts/view/postsView.js b/src/components/posts/view/postsView.js index 66eab64e0..969bedf63 100644 --- a/src/components/posts/view/postsView.js +++ b/src/components/posts/view/postsView.js @@ -3,9 +3,8 @@ import React, { useState, useEffect, useCallback } from 'react'; import { FlatList, View, ActivityIndicator, RefreshControl } from 'react-native'; import { useIntl } from 'react-intl'; import { withNavigation } from 'react-navigation'; -import get from 'lodash/get'; +import { get, unionBy } from 'lodash'; -import { unionWith } from '../../../utils/postParser'; // STEEM import { getPostsSummary, getPost } from '../../../providers/steem/dsteem'; import { getPromotePosts } from '../../../providers/esteem/esteem'; @@ -163,7 +162,7 @@ const PostsView = ({ const filter = type || selectedFilterValue; let options; - const limit = 3; + const limit = 6; if (filter === 'feed' || filter === 'blog' || getFor === 'blog' || filter === 'reblogs') { options = { @@ -197,10 +196,9 @@ const PostsView = ({ if (_posts.length > 0) { if (posts.length > 0) { if (refreshing) { - _posts = unionWith(_posts, posts, 'permlink'); + _posts = unionBy(_posts, posts, 'permlink'); } else { - _posts.shift(); - _posts = unionWith(posts, _posts, 'permlink'); + _posts = unionBy(posts, _posts, 'permlink'); } } @@ -208,34 +206,6 @@ const PostsView = ({ setFeedPosts(_posts); } - // Promoted post start - if (promotedPosts && promotedPosts.length > 0) { - const insert = (arr, index, newItem) => [ - ...arr.slice(0, index), - - newItem, - - ...arr.slice(index), - ]; - - if (refreshing) { - _posts = _posts.filter(item => !item.is_promoted); - } - - _posts.map((d, i) => { - if ([3, 6, 9].includes(i)) { - const ix = i / 3 - 1; - if (promotedPosts[ix] !== undefined) { - if (get(_posts, [i], {}).permlink !== promotedPosts[ix].permlink) { - _posts = insert(_posts, i, promotedPosts[ix]); - //_posts = _posts.splice(i, 0, promotedPosts[ix]); //faster but won't work due to original array changes - } - } - } - }); - } - // Promoted post end - if (!refreshing) { setStartAuthor(result[result.length - 1] && result[result.length - 1].author); setStartPermlink(result[result.length - 1] && result[result.length - 1].permlink); @@ -264,7 +234,7 @@ const PostsView = ({ nsfw, pageType, posts, - promotedPosts, + //promotedPosts, refreshing, selectedFilterValue, setFeedPosts, @@ -349,7 +319,6 @@ const PostsView = ({ {filterOptions && ( intl.formatMessage({ id: `home.${item.toLowerCase()}` }).toUpperCase(), )} @@ -365,18 +334,43 @@ const PostsView = ({ - get(item, 'author', null) && ( - - ) - } - keyExtractor={(content, i) => `${get(content, 'permlink', '')}${i.toString()}`} + renderItem={({ item, index }) => { + const e = []; + if (index % 3 === 0) { + const ix = index / 3 - 1; + if (promotedPosts[ix] !== undefined) { + const p = promotedPosts[ix]; + if (get(p, 'author', null)) { + e.push( + , + ); + } + } + } + if (get(item, 'author', null)) { + e.push( + , + ); + } + return e; + }} + //keyExtractor={(content, i) => `${get(content, 'permlink', '')}${i.toString()}`} onEndReached={() => _loadPosts()} removeClippedSubviews refreshing={refreshing} onRefresh={_handleOnRefreshPosts} - onEndThreshold={0} - initialNumToRender={10} + onEndReachedThreshold={0.1} + initialNumToRender={4} ListFooterComponent={_renderFooter} onScrollEndDrag={_handleOnScroll} ListEmptyComponent={_renderEmptyContent} 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} > { - const { isOwnProfile } = this.state; + _getReplies = async query => { + const { isOwnProfile, comments } = this.state; let repliesAction; if (!isOwnProfile) { @@ -85,12 +85,18 @@ class ProfileContainer extends Component { } else { repliesAction = getRepliesByLastUpdate; } - - await repliesAction({ start_author: user, limit: 10 }).then(result => { - this.setState({ - comments: result, + if (query) { + await repliesAction({ + start_author: query.author, + start_permlink: query.permlink, + limit: 10, + }).then(result => { + let _comments = unionBy(comments, result, 'permlink'); + this.setState({ + comments: _comments, + }); }); - }); + } }; _handleFollowUnfollowUser = async isFollowAction => { @@ -229,7 +235,7 @@ class ProfileContainer extends Component { username, })); - this._getReplies(username); + this._getReplies({ author: username, permlink: undefined }); }; _handleFollowsPress = async isFollowingPress => { @@ -364,7 +370,7 @@ class ProfileContainer extends Component { error, follows, forceLoadPost, - getReplies: () => this._getReplies(username), + getReplies: this._getReplies, handleFollowUnfollowUser: this._handleFollowUnfollowUser, handleMuteUnmuteUser: this._handleMuteUnmuteUser, handleOnBackPress: this._handleOnBackPress, diff --git a/src/providers/esteem/esteem.js b/src/providers/esteem/esteem.js index bde06665e..2a59b96d2 100644 --- a/src/providers/esteem/esteem.js +++ b/src/providers/esteem/esteem.js @@ -369,7 +369,7 @@ export const getSCAccessToken = code => export const getPromotePosts = () => { try { - return api.get('/promoted-posts').then(resp => resp.data); + return api.get('/promoted-posts?limit=50').then(resp => resp.data); } catch (error) { return error; } diff --git a/src/screens/application/container/applicationContainer.js b/src/screens/application/container/applicationContainer.js index bd4b00254..4d430c381 100644 --- a/src/screens/application/container/applicationContainer.js +++ b/src/screens/application/container/applicationContainer.js @@ -521,9 +521,6 @@ class ApplicationContainer extends Component { dispatch(updateActiveBottomTab(ROUTES.TABBAR.NOTIFICATION)); } }; - ws.onclose = e => { - console.log(e); - }; }; _logout = () => { diff --git a/src/utils/postParser.js b/src/utils/postParser.js index 544e9df49..76db9b9b2 100644 --- a/src/utils/postParser.js +++ b/src/utils/postParser.js @@ -180,8 +180,3 @@ const parseActiveVotes = (post, currentUserName) => { return post.active_votes; }; - -export const unionWith = (array1, array2, matcher) => { - let concated = array1.concat(array2); - return uniqBy(concated, matcher); -}; diff --git a/yarn.lock b/yarn.lock index 664df7313..2b54dd3a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1113,10 +1113,10 @@ exec-sh "^0.3.2" minimist "^1.2.0" -"@esteemapp/esteem-render-helpers@^1.3.0": - version "1.3.0" - resolved "https://registry.yarnpkg.com/@esteemapp/esteem-render-helpers/-/esteem-render-helpers-1.3.0.tgz#a109eb8ff045aae7dd0bc7462a79123928c3f8ff" - integrity sha512-hIe5Q6e6rw4y7nHfVcryeKJFrlyW5JXnhxcg65gMHE29fqV4M+iH4wzrMLQuFZFA9SSKL1yYZHuVVrN2/MMdHQ== +"@esteemapp/esteem-render-helpers@^1.3.3": + version "1.3.3" + resolved "https://registry.yarnpkg.com/@esteemapp/esteem-render-helpers/-/esteem-render-helpers-1.3.3.tgz#89dc392bcbd98fd18fd2fccc4bf33fb0b29b560d" + integrity sha512-WF8sCyP1R2NN3a+4phmfyTX5EvY4fleuGEWEZcik2Hps2sDUIzUugP1C3TAH+roEZ13VEVTST77THvkDSe1ssw== dependencies: he "^1.2.0" path "^0.12.7"