first reply succesuflly shared

This commit is contained in:
u-e 2018-12-02 19:21:14 +03:00
parent 7fbe2b0c81
commit 10e7be6da3
11 changed files with 180 additions and 87 deletions

View File

@ -67,7 +67,7 @@ class CommentsView extends Component {
> >
<PostBody isComment handleOnUserPress={handleOnUserPress} body={item.body} /> <PostBody isComment handleOnUserPress={handleOnUserPress} body={item.body} />
<View style={{ flexDirection: 'row' }}> <View style={{ flexDirection: 'row' }}>
<Upvote isShowpayoutValue content={item} user={currentUser} isLoggedIn /> <Upvote isShowPayoutValue content={item} user={currentUser} />
<IconButton <IconButton
iconStyle={{ color: '#c1c5c7' }} iconStyle={{ color: '#c1c5c7' }}
style={{ marginLeft: 20 }} style={{ marginLeft: 20 }}

View File

@ -53,8 +53,9 @@ export default class TitleAreaView extends Component {
autoFocus={autoFocus} autoFocus={autoFocus}
numberOfLines={4} numberOfLines={4}
onChangeText={text => this._handleOnChange(text)} onChangeText={text => this._handleOnChange(text)}
value={value} // TODO: Fix it
{...this.props} // value={value && value}
// {...this.props}
/> />
</View> </View>
); );

View File

@ -1,6 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { import {
View, KeyboardAvoidingView, ScrollView, FlatList, Text, View, KeyboardAvoidingView, ScrollView, FlatList, Text, ActionSheetIOS
} from 'react-native'; } from 'react-native';
import Markdown, { getUniqueID } from 'react-native-markdown-renderer'; import Markdown, { getUniqueID } from 'react-native-markdown-renderer';

View File

@ -105,7 +105,7 @@ class PostCard extends Component {
</View> </View>
<View style={styles.bodyFooter}> <View style={styles.bodyFooter}>
<View style={styles.leftFooterWrapper}> <View style={styles.leftFooterWrapper}>
<Upvote isShowpayoutValue content={content} user={user} isLoggedIn={isLoggedIn} /> <Upvote isShowPayoutValue content={content} user={user} />
<TouchableOpacity <TouchableOpacity
style={styles.commentButton} style={styles.commentButton}
onPress={() => this._handleOnVotersPress()} onPress={() => this._handleOnVotersPress()}

View File

@ -62,7 +62,7 @@ class PostDisplayView extends Component {
return ( return (
<StickyBar isFixedFooter={isFixedFooter}> <StickyBar isFixedFooter={isFixedFooter}>
<View style={styles.stickyWrapper}> <View style={styles.stickyWrapper}>
<Upvote isShowpayoutValue content={post} user={currentUser} isLoggedIn={!!currentUser} /> <Upvote isShowPayoutValue content={post} user={currentUser} />
<TextWithIcon <TextWithIcon
isClickable isClickable
iconStyle={styles.barIcons} iconStyle={styles.barIcons}

View File

@ -1,5 +1,5 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
// import { connect } from 'react-redux'; import { connect } from 'react-redux';
// Services and Actions // Services and Actions
@ -33,8 +33,11 @@ class UpvoteContainer extends Component {
} }
} }
// const mapStateToProps = state => ({ const mapStateToProps = state => ({
// user: state.user.user, isLoggedIn: state.application.isLoggedIn,
// });
export default UpvoteContainer; // TODO: Remove users as coming props. pass follow current account
currentAccount: state.account.currentAccount,
});
export default connect(mapStateToProps)(UpvoteContainer);

View File

@ -106,7 +106,7 @@ class UpvoteView extends Component {
}; };
render() { render() {
const { isLoggedIn, isShowpayoutValue, content } = this.props; const { isLoggedIn, isShowPayoutValue, content } = this.props;
const { const {
isVoting, isModalVisible, amount, value, isVoted, isVoting, isModalVisible, amount, value, isVoted,
} = this.state; } = this.state;
@ -136,7 +136,7 @@ class UpvoteView extends Component {
iconType="AntDesign" iconType="AntDesign"
name={isVoted ? 'upcircle' : 'upcircleo'} name={isVoted ? 'upcircle' : 'upcircleo'}
/> />
{isShowpayoutValue && ( {isShowPayoutValue && (
<Text style={styles.payoutValue}> <Text style={styles.payoutValue}>
$ $
{' '} {' '}

View File

@ -7,6 +7,10 @@ import { Client, PrivateKey } from 'dsteem';
import { AsyncStorage } from 'react-native'; import { AsyncStorage } from 'react-native';
import { getUnreadActivityCount } from '../esteem/esteem'; import { getUnreadActivityCount } from '../esteem/esteem';
import sc2 from './steemConnectAPI';
// Utils
import { decryptKey } from '../../utils/crypto';
import { import {
parsePosts, parsePost, parseComments, parsePostsSummary, parsePosts, parsePost, parseComments, parsePostsSummary,
@ -90,10 +94,11 @@ export const getUser = async (user) => {
} }
}; };
//TODO: Move to utils folder // TODO: Move to utils folder
export const vestToSteem = async (vestingShares, totalVestingShares, totalVestingFundSteem) => { export const vestToSteem = async (vestingShares, totalVestingShares, totalVestingFundSteem) => (
return (parseFloat(totalVestingFundSteem) * (parseFloat(vestingShares) / parseFloat(totalVestingShares))).toFixed(0); parseFloat(totalVestingFundSteem)
} * (parseFloat(vestingShares) / parseFloat(totalVestingShares))
).toFixed(0);
/** /**
* @method getFollows get account data * @method getFollows get account data
@ -248,7 +253,6 @@ export const getUserComments = async (query) => {
try { try {
let comments = await client.database.getDiscussions('comments', query); let comments = await client.database.getDiscussions('comments', query);
comments = parseComments(comments); comments = parseComments(comments);
console.log(comments);
return comments; return comments;
} catch (error) { } catch (error) {
return error; return error;
@ -356,25 +360,6 @@ export const upvoteAmount = async (input) => {
return estimated; return estimated;
}; };
/**
* @method postComment post a comment/reply
* @param comment comment object { author, permlink, ... }
* @param PrivateKey Private posting key
*/
export const postComment = (comment, postingKey) => {
const key = PrivateKey.fromString(postingKey);
return new Promise((resolve, reject) => {
try {
client.broadcast.comment(comment, key).then((result) => {
resolve(result);
});
} catch (error) {
console.log(error);
reject(error);
}
});
};
export const transferToken = (data, activeKey) => { export const transferToken = (data, activeKey) => {
const key = PrivateKey.fromString(activeKey); const key = PrivateKey.fromString(activeKey);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -624,3 +609,70 @@ export const lookupAccounts = async (username) => {
throw error; throw error;
} }
}; };
/**
* @method postComment post a comment/reply
* @param comment comment object { author, permlink, ... }
*/
export const postComment = (
account,
digitPinCode,
parentAuthor,
parentPermlink,
permlink,
title,
body,
jsonMetadata,
options = null,
voteWeight = null,
) => {
const { name: author } = account;
const opArray = [
[
'comment',
{
parent_author: parentAuthor,
parent_permlink: parentPermlink,
author,
permlink,
title,
body,
json_metadata: JSON.stringify(jsonMetadata),
},
],
];
if (options) {
const e = ['comment_options', options];
opArray.push(e);
}
if (voteWeight) {
const e = [
'vote',
{
voter: author,
author,
permlink,
weight: voteWeight,
},
];
opArray.push(e);
}
const key = decryptKey(account.realm_object.postingKey, digitPinCode);
const privateKey = PrivateKey.fromString(key);
return new Promise((resolve, reject) => {
client.broadcast
.sendOperations(opArray, privateKey)
.then((result) => {
resolve(result);
})
.catch((error) => {
console.log(error);
reject(error);
});
});
};

View File

@ -5,7 +5,7 @@ import ImagePicker from 'react-native-image-crop-picker';
// Services and Actions // Services and Actions
// import { Buffer } from 'buffer'; // import { Buffer } from 'buffer';
import { uploadImage } from '../../../providers/esteem/esteem'; import { uploadImage } from '../../../providers/esteem/esteem';
import { postContent } from '../../../providers/steem/dsteem'; import { postContent, postComment } from '../../../providers/steem/dsteem';
import { setDraftPost, getDraftPost } from '../../../realm/realm'; import { setDraftPost, getDraftPost } from '../../../realm/realm';
import { getDigitPinCode } from '../../../providers/steem/auth'; import { getDigitPinCode } from '../../../providers/steem/auth';
@ -73,13 +73,6 @@ class EditorContainer extends Component {
this.setState({ autoFocusText: true }); this.setState({ autoFocusText: true });
} }
// Routing action state ex if coming for video or image or only text
// if (routingAction && routingAction.action) {
// this._handleRoutingAction(routingAction.action);
// } else {
// this.setState({ autoFocusText: true });
// }
if (!isReply) { if (!isReply) {
getDraftPost(username) getDraftPost(username)
.then((result) => { .then((result) => {
@ -206,15 +199,16 @@ class EditorContainer extends Component {
}; };
_submitPost = async (fields) => { _submitPost = async (fields) => {
const { navigation, currentAccount } = this.props;
if (currentAccount) {
this.setState({ isPostSending: true }); this.setState({ isPostSending: true });
const { navigation, currentAccount } = this.props;
const permlink = generatePermlink(fields.title); const permlink = generatePermlink(fields.title);
const digitPinCode = await getDigitPinCode(); const digitPinCode = await getDigitPinCode();
const postingKey = decryptKey(currentAccount.realm_object.postingKey, digitPinCode); const postingKey = decryptKey(currentAccount.realm_object.postingKey, digitPinCode);
if (currentAccount) {
const post = { const post = {
...fields, ...fields,
permlink, permlink,
@ -233,8 +227,53 @@ class EditorContainer extends Component {
} }
}; };
_submitReply = async (fields) => {
const { navigation, currentAccount } = this.props;
if (currentAccount) {
this.setState({ isPostSending: true });
const { post } = this.state;
const jsonMeta = makeJsonMetadataReply(post.json_metadata.tags || ['esteem']);
const permlink = generateReplyPermlink(post.author);
const digitPinCode = await getDigitPinCode();
const author = currentAccount.name;
const options = makeOptions(author, permlink);
const parentAuthor = post.author;
const parentPermlink = post.permlink;
await postComment(
currentAccount,
digitPinCode,
parentAuthor,
parentPermlink,
permlink,
'',
fields.body,
jsonMeta,
options,
0,
)
.then((result) => {
alert('Your post succesfully shared');
navigation.goBack();
})
.catch((error) => {
alert(`Opps! there is a problem${error}`);
this.setState({ isPostSending: false });
});
}
};
_handleSubmit = (form) => { _handleSubmit = (form) => {
const { isReply } = this.state;
if (isReply) {
this._submitReply(form.fields);
} else {
this._submitPost(form); this._submitPost(form);
}
}; };
_handleFormChanged = () => { _handleFormChanged = () => {

View File

@ -85,15 +85,21 @@ class EditorScreen extends Component {
_handleIsFormValid = () => { _handleIsFormValid = () => {
const { fields } = this.state; const { fields } = this.state;
const { isReply } = this.props;
let _isFormValid;
this.setState({ if (isReply) {
isFormValid: _isFormValid = fields && fields.body && fields.body.length > 0;
fields.title } else {
_isFormValid = fields
&& fields.title
&& fields.title.length > 0 && fields.title.length > 0
&& fields.body && fields.body
&& fields.body.length > 0 && fields.body.length > 0
&& fields.tags.length > 0, && fields.tags.length > 0;
}); }
this.setState({ isFormValid: _isFormValid });
}; };
_handleFormUpdate = (componentID, content) => { _handleFormUpdate = (componentID, content) => {
@ -161,18 +167,15 @@ class EditorScreen extends Component {
isFormValid={isFormValid} isFormValid={isFormValid}
isPreviewActive={isPreviewActive} isPreviewActive={isPreviewActive}
> >
{isReply ? ( {isReply && <SummaryArea summary={post.summary} />}
<SummaryArea summary={post.summary} /> {!isReply && <TitleArea value={fields.title} componentID="title" intl={intl} />}
) : ( {!isReply && (
<Fragment>
<TitleArea value={fields.title} componentID="title" intl={intl} />
<TagArea <TagArea
draftChips={fields.tags} draftChips={fields.tags}
componentID="tag-area" componentID="tag-area"
handleTagChanged={this._handleOnTagAdded} handleTagChanged={this._handleOnTagAdded}
intl={intl} intl={intl}
/> />
</Fragment>
)} )}
<TextArea <TextArea
componentID="body" componentID="body"

View File

@ -14,8 +14,7 @@ export const generatePermlink = (text) => {
return null; return null;
}; };
export const generateReplyPermlink = (toAuthor) => {
export const generateReplyPermlink = toAuthor => {
const t = new Date(Date.now()); const t = new Date(Date.now());
const timeFormat = `${t.getFullYear().toString()}${( const timeFormat = `${t.getFullYear().toString()}${(
@ -31,7 +30,6 @@ export const generateReplyPermlink = toAuthor => {
return `re-${toAuthor.replace(/\./g, '')}-${timeFormat}`; return `re-${toAuthor.replace(/\./g, '')}-${timeFormat}`;
}; };
export const makeOptions = (author, permlink, operationType) => { export const makeOptions = (author, permlink, operationType) => {
const a = { const a = {
allow_curation_rewards: true, allow_curation_rewards: true,
@ -40,9 +38,7 @@ export const makeOptions = (author, permlink, operationType) => {
permlink, permlink,
max_accepted_payout: '1000000.000 SBD', max_accepted_payout: '1000000.000 SBD',
percent_steem_dollars: 10000, percent_steem_dollars: 10000,
extensions: [ extensions: [[0, { beneficiaries: [{ account: 'esteemapp', weight: 1000 }] }]],
[0, { beneficiaries: [{ account: 'esteemapp', weight: 1000 }] }]
]
}; };
switch (operationType) { switch (operationType) {
@ -63,10 +59,9 @@ export const makeOptions = (author, permlink, operationType) => {
return a; return a;
}; };
export const makeJsonMetadataReply = tags => ({
export const makeJsonMetadataReply = (tags) => ({
tags, tags,
app: `eSteem Mobile 2`, app: 'esteem/2.0.0-mobile',
format: 'markdown+html', format: 'markdown+html',
community: 'esteem.app' community: 'esteem.app',
}); });