mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-19 19:31:54 +03:00
Merge pull request #1482 from esteemapp/mmore
Embedding and Profile replies fix
This commit is contained in:
commit
1f1ebd6d60
@ -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",
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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 && (
|
||||
<FilterBar
|
||||
dropdownIconName="arrow-drop-down"
|
||||
//options={filterOptions}
|
||||
options={filterOptions.map(item =>
|
||||
intl.formatMessage({ id: `home.${item.toLowerCase()}` }).toUpperCase(),
|
||||
)}
|
||||
@ -365,18 +334,43 @@ const PostsView = ({
|
||||
<FlatList
|
||||
data={posts}
|
||||
showsVerticalScrollIndicator={false}
|
||||
renderItem={({ item }) =>
|
||||
get(item, 'author', null) && (
|
||||
<PostCard isRefresh={refreshing} content={item} isHideImage={isHideImage} />
|
||||
)
|
||||
}
|
||||
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(
|
||||
<PostCard
|
||||
key={`${p.author}-${p.permlink}-prom`}
|
||||
isRefresh={refreshing}
|
||||
content={p}
|
||||
isHideImage={isHideImage}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (get(item, 'author', null)) {
|
||||
e.push(
|
||||
<PostCard
|
||||
key={`${item.author}-${item.permlink}`}
|
||||
isRefresh={refreshing}
|
||||
content={item}
|
||||
isHideImage={isHideImage}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
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}
|
||||
|
@ -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 ? (
|
||||
<ScrollView
|
||||
onScroll={this._handleOnScroll}
|
||||
onScroll={({ nativeEvent }) => {
|
||||
this._handleOnScroll();
|
||||
if (this._isCloseToBottom(nativeEvent)) {
|
||||
this._loadMoreComments();
|
||||
}
|
||||
}}
|
||||
contentContainerStyle={styles.scrollContentContainer}
|
||||
scrollEventThrottle={16}
|
||||
//scrollEventThrottle={16}
|
||||
>
|
||||
<Comments
|
||||
isProfilePreview
|
||||
|
@ -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
|
||||
@ -76,8 +76,8 @@ class ProfileContainer extends Component {
|
||||
this._loadProfile(targetUsername);
|
||||
}
|
||||
|
||||
_getReplies = async user => {
|
||||
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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -521,9 +521,6 @@ class ApplicationContainer extends Component {
|
||||
dispatch(updateActiveBottomTab(ROUTES.TABBAR.NOTIFICATION));
|
||||
}
|
||||
};
|
||||
ws.onclose = e => {
|
||||
console.log(e);
|
||||
};
|
||||
};
|
||||
|
||||
_logout = () => {
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user