created delete comment

This commit is contained in:
u-e 2019-04-07 14:48:01 +03:00
parent 9afc394d94
commit b0f1486adb
7 changed files with 9521 additions and 43 deletions

16
.vscode/settings.json vendored
View File

@ -1,10 +1,10 @@
{
"prettier.eslintIntegration": true,
"editor.formatOnSave": true,
"editor.snippetSuggestions": "top",
"explorer.confirmDelete": false,
"window.zoomLevel": 0,
"prettier.printWidth": 100,
"prettier.singleQuote": true,
"prettier.trailingComma": "all"
// "prettier.eslintIntegration": true,
// "editor.formatOnSave": true,
// "editor.snippetSuggestions": "top",
// "explorer.confirmDelete": false,
// "window.zoomLevel": 0,
// "prettier.printWidth": 100,
// "prettier.singleQuote": true,
// "prettier.trailingComma": "all"
}

View File

@ -34,7 +34,7 @@
"crypto-js": "^3.1.9-1",
"currency-symbol-map": "^4.0.4",
"diff-match-patch": "^1.0.4",
"dsteem": "^0.10.1",
"dsteem": "^0.11.2",
"intl": "^1.2.5",
"jsc-android": "^236355.1.1",
"moment": "^2.22.2",

View File

@ -1,5 +1,7 @@
import React, { PureComponent, Fragment } from 'react';
import { View, Text } from 'react-native';
import ActionSheet from 'react-native-actionsheet';
import { injectIntl } from 'react-intl';
import { getTimeFromNow } from '../../../utils/time';
// Constants
@ -53,6 +55,7 @@ class CommentView extends PureComponent {
isShowMoreButton,
marginLeft,
voteCount,
intl,
} = this.props;
const { isShowSubComments, isPressedShowButton } = this.state;
@ -87,23 +90,39 @@ class CommentView extends PureComponent {
iconType="MaterialIcons"
/>
{currentAccountUsername === comment.author && (
<IconButton
size={18}
iconStyle={styles.leftIcon}
style={styles.leftButton}
name="create"
onPress={() => handleOnEditPress && handleOnEditPress(comment)}
iconType="MaterialIcons"
/>
<Fragment>
<IconButton
size={18}
iconStyle={styles.leftIcon}
style={styles.leftButton}
name="create"
onPress={() => handleOnEditPress && handleOnEditPress(comment)}
iconType="MaterialIcons"
/>
{!comment.children && !voteCount && (
<Fragment>
<IconButton
size={18}
iconStyle={styles.leftIcon}
style={styles.leftButton}
name="delete-forever"
onPress={() => this.ActionSheet.show()}
iconType="MaterialIcons"
/>
<ActionSheet
ref={o => (this.ActionSheet = o)}
options={['Reblog', intl.formatMessage({ id: 'alert.cancel' })]}
title={intl.formatMessage({ id: 'alert.delete' })}
destructiveButtonIndex={0}
cancelButtonIndex={1}
onPress={(index) => {
index === 0 ? handleDeleteComment(comment.permlink) : null;
}}
/>
</Fragment>
)}
</Fragment>
)}
<IconButton
size={18}
iconStyle={styles.leftIcon}
style={styles.leftButton}
name="delete-forever"
onPress={() => handleDeleteComment && handleDeleteComment(comment.author, comment.permlink)}
iconType="MaterialIcons"
/>
</Fragment>
)}
{isShowMoreButton && (
@ -142,4 +161,4 @@ class CommentView extends PureComponent {
}
}
export default CommentView;
export default injectIntl(CommentView);

View File

@ -154,8 +154,12 @@ class CommentsContainer extends Component {
});
};
_handleDeleteComment = (author, permlink) => {
deleteComment(author, permlink);
_handleDeleteComment = (permlink) => {
const { currentAccount, pinCode } = this.props;
deleteComment(currentAccount, pinCode, permlink).then(() => {
this._getComments();
});
}
render() {
@ -198,6 +202,7 @@ class CommentsContainer extends Component {
const mapStateToProps = state => ({
isLoggedIn: state.application.isLoggedIn,
currentAccount: state.account.currentAccount,
pinCode: state.account.pin,
});
export default withNavigation(connect(mapStateToProps)(CommentsContainer));

View File

@ -341,17 +341,55 @@ export const getPurePost = async (author, permlink) => {
}
};
export const deleteComment = (author, permlink) => {
return new Promise((resolve, reject) => {
client.database
.call('comment_delete', [author, permlink])
.then((response) => {
resolve(response);
})
.catch((error) => {
reject(error);
});
});
// export const deleteComment = (author, permlink) => {
// return new Promise((resolve, reject) => {
// client.database
// .call('delete_comment', [author, permlink])
// .then((response) => {
// resolve(response);
// })
// .catch((error) => {
// reject(error);
// });
// });
// };
export const deleteComment = (currentAccount, pin, permlink) => {
const { name: author } = currentAccount;
const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey(currentAccount.local, digitPinCode);
if (currentAccount.local.authType === AUTH_TYPE.STEEM_CONNECT) {
const token = decryptKey(currentAccount.accessToken, pin);
const api = steemConnect.Initialize({
accessToken: token,
});
const params = {
author,
permlink,
};
const opArray = [['delete_comment', params]];
return api.broadcast(opArray).then(resp => resp.result);
}
if (key) {
const opArray = [
[
'delete_comment',
{
author,
permlink,
},
],
];
const privateKey = PrivateKey.fromString(key);
return client.broadcast.sendOperations(opArray, privateKey);
}
};
/**

View File

@ -114,9 +114,11 @@ class EditorContainer extends Component {
_getDraft = async (username, isReply) => {
if (isReply) {
const draftReply = await AsyncStorage.getItem('temp-reply');
this.setState({
draftPost: { body: draftReply },
});
if (draftReply) {
this.setState({
draftPost: { body: draftReply },
});
}
} else {
await getDraftPost(username)
.then((result) => {

9414
yarn.lock Normal file

File diff suppressed because it is too large Load Diff