created delete post option

This commit is contained in:
u-e 2019-05-18 14:11:08 +03:00
parent c447cd78ab
commit 705b848936
4 changed files with 63 additions and 18 deletions

View File

@ -57,7 +57,7 @@ class CommentView extends PureComponent {
voteCount,
intl,
author,
mainAuthor={mainAuthor}
mainAuthor = { mainAuthor },
} = this.props;
const { isShowSubComments, isPressedShowButton } = this.state;

View File

@ -1,8 +1,13 @@
import React, { Component } from 'react';
import { withNavigation } from 'react-navigation';
import { connect } from 'react-redux';
import { injectIntl } from 'react-intl';
// Middleware
// Action
import { toastNotification } from '../../../redux/actions/uiAction';
// Dsteem
import { deleteComment } from '../../../providers/steem/dsteem';
// Constants
import { default as ROUTES } from '../../../constants/routeNames';
@ -70,6 +75,23 @@ class PostDisplayContainer extends Component {
});
};
_handleDeleteComment = (permlink) => {
const {
currentAccount, pinCode, navigation, dispatch, intl,
} = this.props;
deleteComment(currentAccount, pinCode, permlink).then(() => {
navigation.goBack();
dispatch(
toastNotification(
intl.formatMessage({
id: 'alert.removed',
}),
),
);
});
}
_fetchPost = async () => {
const { post, fetchPost } = this.props;
@ -84,14 +106,15 @@ class PostDisplayContainer extends Component {
return (
<PostDisplayView
author={author}
isPostUnavailable={isPostUnavailable}
currentAccount={currentAccount}
fetchPost={this._fetchPost}
handleOnEditPress={this._handleOnEditPress}
handleOnRemovePress={this._handleDeleteComment}
handleOnReplyPress={this._handleOnReplyPress}
handleOnVotersPress={this._handleOnVotersPress}
isLoggedIn={isLoggedIn}
isNewPost={isNewPost}
isPostUnavailable={isPostUnavailable}
parentPost={parentPost}
post={post}
/>
@ -101,8 +124,8 @@ class PostDisplayContainer extends Component {
const mapStateToProps = state => ({
currentAccount: state.account.currentAccount,
pinCode: state.account.pin,
isLoggedIn: state.application.isLoggedIn,
});
export default withNavigation(connect(mapStateToProps)(PostDisplayContainer));
export default withNavigation(connect(mapStateToProps)(injectIntl(PostDisplayContainer)));

View File

@ -3,6 +3,8 @@ import {
View, Text, ScrollView, Dimensions,
} from 'react-native';
import { injectIntl } from 'react-intl';
import get from 'lodash/get';
import ActionSheet from 'react-native-actionsheet';
// Providers
import { userActivity } from '../../../providers/esteem/ePoint';
@ -44,7 +46,7 @@ class PostDisplayView extends PureComponent {
componentDidMount() {
const { currentAccount, isLoggedIn, isNewPost } = this.props;
if (isLoggedIn && currentAccount && currentAccount.name && !isNewPost) {
if (isLoggedIn && get(currentAccount, 'name') && !isNewPost) {
userActivity(currentAccount.name, 10);
}
}
@ -86,8 +88,8 @@ class PostDisplayView extends PureComponent {
iconStyle={styles.barIcons}
iconType="MaterialIcons"
isClickable
onPress={() => handleOnVotersPress && handleOnVotersPress(post.active_votes)}
text={post && post.vote_count}
onPress={() => handleOnVotersPress && handleOnVotersPress(get(post, 'active_votes'))}
text={get(post, 'vote_count')}
textMarginLeft={20}
/>
<TextWithIcon
@ -95,18 +97,29 @@ class PostDisplayView extends PureComponent {
iconStyle={styles.barIcons}
iconType="MaterialIcons"
isClickable
text={post && post.children}
text={get(post, 'children')}
textMarginLeft={20}
/>
<View style={styles.stickyRightWrapper}>
{post && currentAccount && currentAccount.name === post.author && (
<IconButton
iconStyle={styles.barIconRight}
iconType="MaterialIcons"
name="create"
onPress={() => handleOnEditPress && handleOnEditPress()}
style={styles.barIconButton}
/>
{get(currentAccount, 'name') === get(post, 'author') && (
<Fragment>
{!get(post, 'children') && !get(post, 'vote_count') && (
<IconButton
iconStyle={styles.barIconRight}
iconType="MaterialIcons"
name="delete-forever"
onPress={() => this.ActionSheet.show()}
style={styles.barIconButton}
/>
)}
<IconButton
iconStyle={styles.barIconRight}
iconType="MaterialIcons"
name="create"
onPress={() => handleOnEditPress && handleOnEditPress()}
style={styles.barIconButton}
/>
</Fragment>
)}
{isLoggedIn && (
<IconButton
@ -132,6 +145,7 @@ class PostDisplayView extends PureComponent {
isPostUnavailable,
author,
intl,
handleOnRemovePress,
} = this.props;
const { postHeight, scrollHeight, isLoadedComments } = this.state;
@ -197,6 +211,13 @@ class PostDisplayView extends PureComponent {
)}
</ScrollView>
{post && this._getTabBar(true)}
<ActionSheet
ref={o => (this.ActionSheet = o)}
options={[intl.formatMessage({ id: 'alert.delete' }), intl.formatMessage({ id: 'alert.cancel' })]}
title={intl.formatMessage({ id: 'post.remove_alert' })}
cancelButtonIndex={1}
onPress={index => (index === 0 ? handleOnRemovePress(get(post, 'permlink')) : null)}
/>
</Fragment>
);
}

View File

@ -194,7 +194,8 @@
"delete": "Delete",
"copied": "Copied!",
"no_internet": "No connection!",
"confirm": "Confirm"
"confirm": "Confirm",
"removed": "Removed"
},
"post": {
"reblog_alert": "Are you sure you want to reblog?",