From b42bdc6132751645d00258f01371422286dde31d Mon Sep 17 00:00:00 2001 From: feruz Date: Sun, 12 Jan 2020 07:16:33 +0200 Subject: [PATCH 1/5] 3speak embedding support --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d065eaee1..a7df37f57 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.1", "@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/yarn.lock b/yarn.lock index 664df7313..564800a49 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.1": + version "1.3.1" + resolved "https://registry.yarnpkg.com/@esteemapp/esteem-render-helpers/-/esteem-render-helpers-1.3.1.tgz#aead95afb387e4c04644e14e1d1f4f08c14f21ff" + integrity sha512-A05OWpdrzu8wprByogXmh0OLmftI1lpa6HmwZLeegXszO4Lj1VBOUPi/KkaHuzEzkm/FEWy+cnGK1PnsrQ/Iww== dependencies: he "^1.2.0" path "^0.12.7" From 75ac107e46db9168a99db48fd5c596c1e9d11243 Mon Sep 17 00:00:00 2001 From: feruz Date: Sun, 12 Jan 2020 21:42:23 +0200 Subject: [PATCH 2/5] fix 3speak embed issue --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a7df37f57..003adfc8a 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ }, "dependencies": { "@babel/runtime": "^7.5.5", - "@esteemapp/esteem-render-helpers": "^1.3.1", + "@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/yarn.lock b/yarn.lock index 564800a49..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.1": - version "1.3.1" - resolved "https://registry.yarnpkg.com/@esteemapp/esteem-render-helpers/-/esteem-render-helpers-1.3.1.tgz#aead95afb387e4c04644e14e1d1f4f08c14f21ff" - integrity sha512-A05OWpdrzu8wprByogXmh0OLmftI1lpa6HmwZLeegXszO4Lj1VBOUPi/KkaHuzEzkm/FEWy+cnGK1PnsrQ/Iww== +"@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" From 3e5b73816c0e899176161489337b0b84b5e013e1 Mon Sep 17 00:00:00 2001 From: feruz Date: Mon, 13 Jan 2020 13:12:40 +0200 Subject: [PATCH 3/5] 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, From 5a19501d91e2b9a39f5aa30ff95a2f797aa0035e Mon Sep 17 00:00:00 2001 From: feruz Date: Mon, 13 Jan 2020 13:27:46 +0200 Subject: [PATCH 4/5] fix comments merge --- src/containers/profileContainer.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/containers/profileContainer.js b/src/containers/profileContainer.js index af8a27453..c14cb0bb0 100644 --- a/src/containers/profileContainer.js +++ b/src/containers/profileContainer.js @@ -23,6 +23,7 @@ import { getIsFavorite, addFavorite, removeFavorite } from '../providers/esteem/ // Utilitites import { getRcPower, getVotingPower } from '../utils/manaBar'; +import { unionWith } from '../utils/postParser'; // Constants import { default as ROUTES } from '../constants/routeNames'; @@ -77,7 +78,7 @@ class ProfileContainer extends Component { } _getReplies = async query => { - const { isOwnProfile } = this.state; + const { isOwnProfile, comments } = this.state; let repliesAction; if (!isOwnProfile) { @@ -85,16 +86,18 @@ class ProfileContainer extends Component { } else { repliesAction = getRepliesByLastUpdate; } - - await repliesAction({ - start_author: query.author, - start_permlink: query.permlink, - 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 = unionWith(comments, result, 'permlink'); + this.setState({ + comments: _comments, + }); }); - }); + } }; _handleFollowUnfollowUser = async isFollowAction => { From 8264101b89b722a1cfeecebe8fb4e3583b78fcfc Mon Sep 17 00:00:00 2001 From: feruz Date: Tue, 14 Jan 2020 09:59:48 +0200 Subject: [PATCH 5/5] enhance promotedPosts, fix union of posts, increase limit, other fixes --- .../postElements/body/view/config.js | 1 - src/components/posts/view/postsView.js | 82 +++++++++---------- src/containers/profileContainer.js | 5 +- src/providers/esteem/esteem.js | 2 +- .../container/applicationContainer.js | 3 - src/utils/postParser.js | 5 -- 6 files changed, 41 insertions(+), 57 deletions(-) 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/containers/profileContainer.js b/src/containers/profileContainer.js index c14cb0bb0..b4cd64320 100644 --- a/src/containers/profileContainer.js +++ b/src/containers/profileContainer.js @@ -2,7 +2,7 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { withNavigation } from 'react-navigation'; -import { get, has } from 'lodash'; +import { get, has, unionBy } from 'lodash'; import { Alert } from 'react-native'; // Providers @@ -23,7 +23,6 @@ import { getIsFavorite, addFavorite, removeFavorite } from '../providers/esteem/ // Utilitites import { getRcPower, getVotingPower } from '../utils/manaBar'; -import { unionWith } from '../utils/postParser'; // Constants import { default as ROUTES } from '../constants/routeNames'; @@ -92,7 +91,7 @@ class ProfileContainer extends Component { start_permlink: query.permlink, limit: 10, }).then(result => { - let _comments = unionWith(comments, result, 'permlink'); + let _comments = unionBy(comments, result, 'permlink'); this.setState({ comments: _comments, }); 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); -};