mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-23 05:13:04 +03:00
first reply succesuflly shared
This commit is contained in:
parent
7fbe2b0c81
commit
10e7be6da3
@ -67,7 +67,7 @@ class CommentsView extends Component {
|
||||
>
|
||||
<PostBody isComment handleOnUserPress={handleOnUserPress} body={item.body} />
|
||||
<View style={{ flexDirection: 'row' }}>
|
||||
<Upvote isShowpayoutValue content={item} user={currentUser} isLoggedIn />
|
||||
<Upvote isShowPayoutValue content={item} user={currentUser} />
|
||||
<IconButton
|
||||
iconStyle={{ color: '#c1c5c7' }}
|
||||
style={{ marginLeft: 20 }}
|
||||
|
@ -11,9 +11,9 @@ import globalStyles from '../../../../globalStyles';
|
||||
|
||||
export default class TitleAreaView extends Component {
|
||||
/* Props
|
||||
* ------------------------------------------------
|
||||
* @prop { type } name - Description....
|
||||
*/
|
||||
* ------------------------------------------------
|
||||
* @prop { type } name - Description....
|
||||
*/
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@ -53,8 +53,9 @@ export default class TitleAreaView extends Component {
|
||||
autoFocus={autoFocus}
|
||||
numberOfLines={4}
|
||||
onChangeText={text => this._handleOnChange(text)}
|
||||
value={value}
|
||||
{...this.props}
|
||||
// TODO: Fix it
|
||||
// value={value && value}
|
||||
// {...this.props}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React, { Component } from 'react';
|
||||
import {
|
||||
View, KeyboardAvoidingView, ScrollView, FlatList, Text,
|
||||
View, KeyboardAvoidingView, ScrollView, FlatList, Text, ActionSheetIOS
|
||||
} from 'react-native';
|
||||
import Markdown, { getUniqueID } from 'react-native-markdown-renderer';
|
||||
|
||||
|
@ -105,7 +105,7 @@ class PostCard extends Component {
|
||||
</View>
|
||||
<View style={styles.bodyFooter}>
|
||||
<View style={styles.leftFooterWrapper}>
|
||||
<Upvote isShowpayoutValue content={content} user={user} isLoggedIn={isLoggedIn} />
|
||||
<Upvote isShowPayoutValue content={content} user={user} />
|
||||
<TouchableOpacity
|
||||
style={styles.commentButton}
|
||||
onPress={() => this._handleOnVotersPress()}
|
||||
|
@ -62,7 +62,7 @@ class PostDisplayView extends Component {
|
||||
return (
|
||||
<StickyBar isFixedFooter={isFixedFooter}>
|
||||
<View style={styles.stickyWrapper}>
|
||||
<Upvote isShowpayoutValue content={post} user={currentUser} isLoggedIn={!!currentUser} />
|
||||
<Upvote isShowPayoutValue content={post} user={currentUser} />
|
||||
<TextWithIcon
|
||||
isClickable
|
||||
iconStyle={styles.barIcons}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { Component } from 'react';
|
||||
// import { connect } from 'react-redux';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
// Services and Actions
|
||||
|
||||
@ -13,10 +13,10 @@ import React, { Component } from 'react';
|
||||
import { UpvoteView } from '..';
|
||||
|
||||
/*
|
||||
* Props Name Description Value
|
||||
*@props --> props name here description here Value Type Here
|
||||
*
|
||||
*/
|
||||
* Props Name Description Value
|
||||
*@props --> props name here description here Value Type Here
|
||||
*
|
||||
*/
|
||||
|
||||
class UpvoteContainer extends Component {
|
||||
constructor(props) {
|
||||
@ -33,8 +33,11 @@ class UpvoteContainer extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
// const mapStateToProps = state => ({
|
||||
// user: state.user.user,
|
||||
// });
|
||||
const mapStateToProps = state => ({
|
||||
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);
|
||||
|
@ -106,7 +106,7 @@ class UpvoteView extends Component {
|
||||
};
|
||||
|
||||
render() {
|
||||
const { isLoggedIn, isShowpayoutValue, content } = this.props;
|
||||
const { isLoggedIn, isShowPayoutValue, content } = this.props;
|
||||
const {
|
||||
isVoting, isModalVisible, amount, value, isVoted,
|
||||
} = this.state;
|
||||
@ -136,7 +136,7 @@ class UpvoteView extends Component {
|
||||
iconType="AntDesign"
|
||||
name={isVoted ? 'upcircle' : 'upcircleo'}
|
||||
/>
|
||||
{isShowpayoutValue && (
|
||||
{isShowPayoutValue && (
|
||||
<Text style={styles.payoutValue}>
|
||||
$
|
||||
{' '}
|
||||
|
@ -7,6 +7,10 @@ import { Client, PrivateKey } from 'dsteem';
|
||||
import { AsyncStorage } from 'react-native';
|
||||
|
||||
import { getUnreadActivityCount } from '../esteem/esteem';
|
||||
import sc2 from './steemConnectAPI';
|
||||
|
||||
// Utils
|
||||
import { decryptKey } from '../../utils/crypto';
|
||||
|
||||
import {
|
||||
parsePosts, parsePost, parseComments, parsePostsSummary,
|
||||
@ -90,10 +94,11 @@ export const getUser = async (user) => {
|
||||
}
|
||||
};
|
||||
|
||||
//TODO: Move to utils folder
|
||||
export const vestToSteem = async (vestingShares, totalVestingShares, totalVestingFundSteem) => {
|
||||
return (parseFloat(totalVestingFundSteem) * (parseFloat(vestingShares) / parseFloat(totalVestingShares))).toFixed(0);
|
||||
}
|
||||
// TODO: Move to utils folder
|
||||
export const vestToSteem = async (vestingShares, totalVestingShares, totalVestingFundSteem) => (
|
||||
parseFloat(totalVestingFundSteem)
|
||||
* (parseFloat(vestingShares) / parseFloat(totalVestingShares))
|
||||
).toFixed(0);
|
||||
|
||||
/**
|
||||
* @method getFollows get account data
|
||||
@ -248,7 +253,6 @@ export const getUserComments = async (query) => {
|
||||
try {
|
||||
let comments = await client.database.getDiscussions('comments', query);
|
||||
comments = parseComments(comments);
|
||||
console.log(comments);
|
||||
return comments;
|
||||
} catch (error) {
|
||||
return error;
|
||||
@ -356,25 +360,6 @@ export const upvoteAmount = async (input) => {
|
||||
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) => {
|
||||
const key = PrivateKey.fromString(activeKey);
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -624,3 +609,70 @@ export const lookupAccounts = async (username) => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -5,7 +5,7 @@ import ImagePicker from 'react-native-image-crop-picker';
|
||||
// Services and Actions
|
||||
// import { Buffer } from 'buffer';
|
||||
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 { getDigitPinCode } from '../../../providers/steem/auth';
|
||||
|
||||
@ -73,13 +73,6 @@ class EditorContainer extends Component {
|
||||
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) {
|
||||
getDraftPost(username)
|
||||
.then((result) => {
|
||||
@ -206,15 +199,16 @@ class EditorContainer extends Component {
|
||||
};
|
||||
|
||||
_submitPost = async (fields) => {
|
||||
this.setState({ isPostSending: true });
|
||||
|
||||
const { navigation, currentAccount } = this.props;
|
||||
const permlink = generatePermlink(fields.title);
|
||||
const digitPinCode = await getDigitPinCode();
|
||||
|
||||
const postingKey = decryptKey(currentAccount.realm_object.postingKey, digitPinCode);
|
||||
|
||||
if (currentAccount) {
|
||||
this.setState({ isPostSending: true });
|
||||
|
||||
const permlink = generatePermlink(fields.title);
|
||||
const digitPinCode = await getDigitPinCode();
|
||||
|
||||
const postingKey = decryptKey(currentAccount.realm_object.postingKey, digitPinCode);
|
||||
|
||||
const post = {
|
||||
...fields,
|
||||
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) => {
|
||||
this._submitPost(form);
|
||||
const { isReply } = this.state;
|
||||
|
||||
if (isReply) {
|
||||
this._submitReply(form.fields);
|
||||
} else {
|
||||
this._submitPost(form);
|
||||
}
|
||||
};
|
||||
|
||||
_handleFormChanged = () => {
|
||||
|
@ -85,15 +85,21 @@ class EditorScreen extends Component {
|
||||
|
||||
_handleIsFormValid = () => {
|
||||
const { fields } = this.state;
|
||||
const { isReply } = this.props;
|
||||
let _isFormValid;
|
||||
|
||||
this.setState({
|
||||
isFormValid:
|
||||
fields.title
|
||||
if (isReply) {
|
||||
_isFormValid = fields && fields.body && fields.body.length > 0;
|
||||
} else {
|
||||
_isFormValid = fields
|
||||
&& fields.title
|
||||
&& fields.title.length > 0
|
||||
&& fields.body
|
||||
&& fields.body.length > 0
|
||||
&& fields.tags.length > 0,
|
||||
});
|
||||
&& fields.tags.length > 0;
|
||||
}
|
||||
|
||||
this.setState({ isFormValid: _isFormValid });
|
||||
};
|
||||
|
||||
_handleFormUpdate = (componentID, content) => {
|
||||
@ -161,18 +167,15 @@ class EditorScreen extends Component {
|
||||
isFormValid={isFormValid}
|
||||
isPreviewActive={isPreviewActive}
|
||||
>
|
||||
{isReply ? (
|
||||
<SummaryArea summary={post.summary} />
|
||||
) : (
|
||||
<Fragment>
|
||||
<TitleArea value={fields.title} componentID="title" intl={intl} />
|
||||
<TagArea
|
||||
draftChips={fields.tags}
|
||||
componentID="tag-area"
|
||||
handleTagChanged={this._handleOnTagAdded}
|
||||
intl={intl}
|
||||
/>
|
||||
</Fragment>
|
||||
{isReply && <SummaryArea summary={post.summary} />}
|
||||
{!isReply && <TitleArea value={fields.title} componentID="title" intl={intl} />}
|
||||
{!isReply && (
|
||||
<TagArea
|
||||
draftChips={fields.tags}
|
||||
componentID="tag-area"
|
||||
handleTagChanged={this._handleOnTagAdded}
|
||||
intl={intl}
|
||||
/>
|
||||
)}
|
||||
<TextArea
|
||||
componentID="body"
|
||||
|
@ -14,8 +14,7 @@ export const generatePermlink = (text) => {
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
export const generateReplyPermlink = toAuthor => {
|
||||
export const generateReplyPermlink = (toAuthor) => {
|
||||
const t = new Date(Date.now());
|
||||
|
||||
const timeFormat = `${t.getFullYear().toString()}${(
|
||||
@ -31,7 +30,6 @@ export const generateReplyPermlink = toAuthor => {
|
||||
return `re-${toAuthor.replace(/\./g, '')}-${timeFormat}`;
|
||||
};
|
||||
|
||||
|
||||
export const makeOptions = (author, permlink, operationType) => {
|
||||
const a = {
|
||||
allow_curation_rewards: true,
|
||||
@ -40,9 +38,7 @@ export const makeOptions = (author, permlink, operationType) => {
|
||||
permlink,
|
||||
max_accepted_payout: '1000000.000 SBD',
|
||||
percent_steem_dollars: 10000,
|
||||
extensions: [
|
||||
[0, { beneficiaries: [{ account: 'esteemapp', weight: 1000 }] }]
|
||||
]
|
||||
extensions: [[0, { beneficiaries: [{ account: 'esteemapp', weight: 1000 }] }]],
|
||||
};
|
||||
|
||||
switch (operationType) {
|
||||
@ -63,10 +59,9 @@ export const makeOptions = (author, permlink, operationType) => {
|
||||
return a;
|
||||
};
|
||||
|
||||
|
||||
export const makeJsonMetadataReply = (tags) => ({
|
||||
export const makeJsonMetadataReply = tags => ({
|
||||
tags,
|
||||
app: `eSteem Mobile 2`,
|
||||
app: 'esteem/2.0.0-mobile',
|
||||
format: 'markdown+html',
|
||||
community: 'esteem.app'
|
||||
});
|
||||
community: 'esteem.app',
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user