Fixed reply delete issue

This commit is contained in:
Mustafa Buyukcelebi 2019-08-30 01:35:33 +03:00
parent 8ab1989e5c
commit 9ab3529acd
4 changed files with 39 additions and 22 deletions

View File

@ -129,8 +129,13 @@ class CommentsContainer extends Component {
permlink, permlink,
selectedFilter, selectedFilter,
currentAccount: { name }, currentAccount: { name },
isOwnProfile,
fetchPost,
} = this.props; } = this.props;
if (isOwnProfile) {
fetchPost();
} else {
await getComments(author, permlink, name) await getComments(author, permlink, name)
.then(comments => { .then(comments => {
if (selectedFilter && selectedFilter !== 'TRENDING') { if (selectedFilter && selectedFilter !== 'TRENDING') {
@ -145,6 +150,7 @@ class CommentsContainer extends Component {
} }
}) })
.catch(() => {}); .catch(() => {});
}
}; };
_handleOnReplyPress = item => { _handleOnReplyPress = item => {
@ -175,10 +181,17 @@ class CommentsContainer extends Component {
}; };
_handleDeleteComment = permlink => { _handleDeleteComment = permlink => {
const { currentAccount, pinCode } = this.props; const { currentAccount, pinCode, comments } = this.props;
const { comments: _comments } = this.state;
let filteredComments;
deleteComment(currentAccount, pinCode, permlink).then(() => { deleteComment(currentAccount, pinCode, permlink).then(() => {
this._getComments(); if (_comments.length > 0) {
filteredComments = _comments.filter(item => item.permlink !== permlink);
} else {
filteredComments = comments.filter(item => item.permlink !== permlink);
}
this.setState({ comments: filteredComments });
}); });
}; };
@ -240,7 +253,7 @@ class CommentsContainer extends Component {
isShowMoreButton={isShowMoreButton} isShowMoreButton={isShowMoreButton}
commentNumber={commentNumber || 1} commentNumber={commentNumber || 1}
commentCount={commentCount} commentCount={commentCount}
comments={_comments || comments} comments={_comments.length > 0 ? _comments : comments}
currentAccountUsername={currentAccount.name} currentAccountUsername={currentAccount.name}
handleOnEditPress={this._handleOnEditPress} handleOnEditPress={this._handleOnEditPress}
handleOnReplyPress={this._handleOnReplyPress} handleOnReplyPress={this._handleOnReplyPress}
@ -248,7 +261,6 @@ class CommentsContainer extends Component {
fetchPost={fetchPost} fetchPost={fetchPost}
handleDeleteComment={this._handleDeleteComment} handleDeleteComment={this._handleDeleteComment}
handleOnPressCommentMenu={this._handleOnPressCommentMenu} handleOnPressCommentMenu={this._handleOnPressCommentMenu}
{...this.props}
/> />
); );
} }

View File

@ -1,4 +1,4 @@
import React, { PureComponent, Fragment } from 'react'; import React, { Component, Fragment } from 'react';
import { FlatList } from 'react-native'; import { FlatList } from 'react-native';
import ActionSheet from 'react-native-actionsheet'; import ActionSheet from 'react-native-actionsheet';
import get from 'lodash/get'; import get from 'lodash/get';
@ -11,7 +11,7 @@ import { Comment } from '../../comment';
// Styles // Styles
import styles from './commentStyles'; import styles from './commentStyles';
class CommentsView extends PureComponent { class CommentsView extends Component {
/* Props /* Props
* ------------------------------------------------ * ------------------------------------------------
* @prop { type } name - Description.... * @prop { type } name - Description....

View File

@ -373,7 +373,7 @@ export const deleteComment = (currentAccount, pin, permlink) => {
const key = getAnyPrivateKey(currentAccount.local, digitPinCode); const key = getAnyPrivateKey(currentAccount.local, digitPinCode);
if (currentAccount.local.authType === AUTH_TYPE.STEEM_CONNECT) { if (currentAccount.local.authType === AUTH_TYPE.STEEM_CONNECT) {
const token = decryptKey(currentAccount.accessToken, pin); const token = decryptKey(currentAccount.local.accessToken, digitPinCode);
const api = steemConnect.Initialize({ const api = steemConnect.Initialize({
accessToken: token, accessToken: token,
}); });

View File

@ -226,7 +226,12 @@ class ProfileScreen extends PureComponent {
> >
{comments && comments.length > 0 ? ( {comments && comments.length > 0 ? (
<ScrollView onScroll={this._handleOnScroll}> <ScrollView onScroll={this._handleOnScroll}>
<Comments isProfilePreview comments={comments} fetchPost={getReplies} /> <Comments
isProfilePreview
comments={comments}
fetchPost={getReplies}
isOwnProfile={!isReverseHeader}
/>
</ScrollView> </ScrollView>
) : ( ) : (
<NoPost <NoPost