From 705b8489362fc641d2d079a2c8237597a00f212b Mon Sep 17 00:00:00 2001 From: u-e Date: Sat, 18 May 2019 14:11:08 +0300 Subject: [PATCH] created delete post option --- src/components/comment/view/commentView.js | 2 +- .../container/postDisplayContainer.js | 31 +++++++++++-- .../postView/view/postDisplayView.js | 45 ++++++++++++++----- src/config/locales/en-US.json | 3 +- 4 files changed, 63 insertions(+), 18 deletions(-) diff --git a/src/components/comment/view/commentView.js b/src/components/comment/view/commentView.js index fe97ff758..407e2e33a 100644 --- a/src/components/comment/view/commentView.js +++ b/src/components/comment/view/commentView.js @@ -57,7 +57,7 @@ class CommentView extends PureComponent { voteCount, intl, author, - mainAuthor={mainAuthor} + mainAuthor = { mainAuthor }, } = this.props; const { isShowSubComments, isPressedShowButton } = this.state; diff --git a/src/components/postView/container/postDisplayContainer.js b/src/components/postView/container/postDisplayContainer.js index aa4dc31f0..d9b42f558 100644 --- a/src/components/postView/container/postDisplayContainer.js +++ b/src/components/postView/container/postDisplayContainer.js @@ -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 ( @@ -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))); diff --git a/src/components/postView/view/postDisplayView.js b/src/components/postView/view/postDisplayView.js index 0599b4624..f158533e4 100644 --- a/src/components/postView/view/postDisplayView.js +++ b/src/components/postView/view/postDisplayView.js @@ -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} /> - {post && currentAccount && currentAccount.name === post.author && ( - handleOnEditPress && handleOnEditPress()} - style={styles.barIconButton} - /> + {get(currentAccount, 'name') === get(post, 'author') && ( + + {!get(post, 'children') && !get(post, 'vote_count') && ( + this.ActionSheet.show()} + style={styles.barIconButton} + /> + )} + handleOnEditPress && handleOnEditPress()} + style={styles.barIconButton} + /> + )} {isLoggedIn && ( {post && this._getTabBar(true)} + (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)} + /> ); } diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index 81fe9b5e6..a85f266d5 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -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?",