mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-25 22:33:52 +03:00
created edit
This commit is contained in:
parent
8feea5ef66
commit
7f90dd8e8c
@ -74,6 +74,7 @@ class BasicHeaderView extends Component {
|
||||
isLoggedIn,
|
||||
isModalHeader,
|
||||
isPostSending,
|
||||
rightButtonText,
|
||||
isPreviewActive,
|
||||
isReply,
|
||||
quickTitle,
|
||||
@ -170,13 +171,13 @@ class BasicHeaderView extends Component {
|
||||
|
||||
{isHasIcons && (
|
||||
<Fragment>
|
||||
<IconButton
|
||||
{/* <IconButton
|
||||
style={styles.iconButton}
|
||||
iconStyle={styles.rightIcon}
|
||||
size={20}
|
||||
iconType="MaterialIcons"
|
||||
name="timer"
|
||||
/>
|
||||
/> */}
|
||||
<IconButton
|
||||
style={styles.iconButton}
|
||||
size={25}
|
||||
@ -193,9 +194,7 @@ class BasicHeaderView extends Component {
|
||||
]}
|
||||
onPress={isFormValid && this._handleOnPress}
|
||||
style={styles.textButtonWrapper}
|
||||
text={intl.formatMessage({
|
||||
id: isReply ? 'basic_header.reply' : 'basic_header.publish',
|
||||
})}
|
||||
text={rightButtonText}
|
||||
/>
|
||||
) : (
|
||||
<ActivityIndicator style={[styles.textButtonWrapper]} />
|
||||
|
@ -67,19 +67,36 @@ class CommentsContainer extends Component {
|
||||
});
|
||||
};
|
||||
|
||||
_handleOnEditPress = (item) => {
|
||||
const { navigation, fetchPost } = this.props;
|
||||
|
||||
navigation.navigate({
|
||||
routeName: ROUTES.SCREENS.EDITOR,
|
||||
params: {
|
||||
isEdit: true,
|
||||
isReply: true,
|
||||
post: item,
|
||||
fetchPost,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const { comments } = this.state;
|
||||
const {
|
||||
isLoggedIn, commentCount, author, permlink,
|
||||
isLoggedIn, commentCount, author, permlink, currentAccount, fetchPost,
|
||||
} = this.props;
|
||||
return (
|
||||
<CommentsView
|
||||
handleOnReplyPress={this._handleOnReplyPress}
|
||||
comments={comments}
|
||||
isLoggedIn={isLoggedIn}
|
||||
commentCount={commentCount}
|
||||
author={author}
|
||||
commentCount={commentCount}
|
||||
comments={comments}
|
||||
currentAccountUsername={currentAccount.name}
|
||||
handleOnEditPress={this._handleOnEditPress}
|
||||
handleOnReplyPress={this._handleOnReplyPress}
|
||||
isLoggedIn={isLoggedIn}
|
||||
permlink={permlink}
|
||||
fetchPost={fetchPost}
|
||||
{...this.props}
|
||||
/>
|
||||
);
|
||||
@ -88,6 +105,7 @@ class CommentsContainer extends Component {
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
isLoggedIn: state.application.isLoggedIn,
|
||||
currentAccount: state.account.currentAccount,
|
||||
});
|
||||
|
||||
export default withNavigation(connect(mapStateToProps)(CommentsContainer));
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
import React, { PureComponent, Fragment } from 'react';
|
||||
import { View, FlatList } from 'react-native';
|
||||
|
||||
// Constants
|
||||
@ -32,16 +32,19 @@ class CommentsView extends PureComponent {
|
||||
|
||||
render() {
|
||||
const {
|
||||
comments,
|
||||
avatarSize,
|
||||
marginLeft,
|
||||
handleOnUserPress,
|
||||
commentNumber,
|
||||
comments,
|
||||
currentAccountUsername,
|
||||
handleOnEditPress,
|
||||
handleOnReplyPress,
|
||||
isProfilePreview,
|
||||
handleOnUserPress,
|
||||
isLoggedIn,
|
||||
isProfilePreview,
|
||||
marginLeft,
|
||||
fetchPost,
|
||||
} = this.props;
|
||||
// commentNumber === 8 && alert('sekkiz:');
|
||||
|
||||
return (
|
||||
<View>
|
||||
{!!comments && (
|
||||
@ -69,13 +72,24 @@ class CommentsView extends PureComponent {
|
||||
<View style={{ flexDirection: 'row' }}>
|
||||
<Upvote isShowPayoutValue content={item} />
|
||||
{isLoggedIn && (
|
||||
<IconButton
|
||||
iconStyle={{ color: '#c1c5c7' }}
|
||||
style={{ marginLeft: 20 }}
|
||||
name="reply"
|
||||
onPress={() => handleOnReplyPress && handleOnReplyPress(item)}
|
||||
iconType="MaterialIcons"
|
||||
/>
|
||||
<Fragment>
|
||||
<IconButton
|
||||
iconStyle={{ color: '#c1c5c7' }}
|
||||
style={{ marginLeft: 20 }}
|
||||
name="reply"
|
||||
onPress={() => handleOnReplyPress && handleOnReplyPress(item)}
|
||||
iconType="MaterialIcons"
|
||||
/>
|
||||
{currentAccountUsername === item.author && (
|
||||
<IconButton
|
||||
iconStyle={{ color: '#c1c5c7' }}
|
||||
style={{ marginLeft: 10 }}
|
||||
name="create"
|
||||
onPress={() => handleOnEditPress && handleOnEditPress(item)}
|
||||
iconType="MaterialIcons"
|
||||
/>
|
||||
)}
|
||||
</Fragment>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
@ -89,6 +103,7 @@ class CommentsView extends PureComponent {
|
||||
author={item.author}
|
||||
permlink={item.permlink}
|
||||
commentCount={item.children}
|
||||
fetchPost={fetchPost}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
|
@ -18,7 +18,7 @@ export default class TagAreaView extends Component {
|
||||
super(props);
|
||||
this.state = {
|
||||
currentText: '',
|
||||
chips: [' '],
|
||||
chips: props.draftChips || [' '],
|
||||
chipsCount: props.chipsCount || 5,
|
||||
activeChip: 0,
|
||||
};
|
||||
|
@ -20,7 +20,7 @@ export default class MarkdownEditorView extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
text: '',
|
||||
text: props.draftBody || '',
|
||||
selection: { start: 0, end: 0 },
|
||||
};
|
||||
}
|
||||
|
@ -56,6 +56,18 @@ class PostDisplayContainer extends Component {
|
||||
});
|
||||
};
|
||||
|
||||
_handleOnEditPress = () => {
|
||||
const { post, navigation } = this.props;
|
||||
navigation.navigate({
|
||||
routeName: ROUTES.SCREENS.EDITOR,
|
||||
params: {
|
||||
isEdit: true,
|
||||
post,
|
||||
fetchPost: this._fetchPost,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
_fetchPost = async () => {
|
||||
const { post, fetchPost } = this.props;
|
||||
|
||||
@ -69,6 +81,7 @@ class PostDisplayContainer extends Component {
|
||||
<PostDisplayView
|
||||
handleOnVotersPress={this._handleOnVotersPress}
|
||||
handleOnReplyPress={this._handleOnReplyPress}
|
||||
handleOnEditPress={this._handleOnEditPress}
|
||||
currentAccount={currentAccount}
|
||||
fetchPost={this._fetchPost}
|
||||
post={post}
|
||||
|
@ -101,6 +101,7 @@
|
||||
"basic_header": {
|
||||
"publish": "Publish",
|
||||
"search": "Search",
|
||||
"update": "Update",
|
||||
"reply": "Reply"
|
||||
},
|
||||
"editor": {
|
||||
|
@ -103,6 +103,7 @@
|
||||
"basic_header": {
|
||||
"publish": "Yayınla",
|
||||
"search": "Ara",
|
||||
"update": "Güncelle",
|
||||
"reply": "Cevapla"
|
||||
},
|
||||
"editor": {
|
||||
|
@ -312,6 +312,14 @@ export const getPost = async (author, permlink, currentUserName) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getPurePost = async (author, permlink) => {
|
||||
try {
|
||||
return await client.database.call('get_content', [author, permlink]);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @method getUser get user data
|
||||
* @param user post author
|
||||
|
@ -4,13 +4,13 @@ import { Alert } from 'react-native';
|
||||
import ImagePicker from 'react-native-image-crop-picker';
|
||||
|
||||
// Services and Actions
|
||||
// import { Buffer } from 'buffer';
|
||||
import { Buffer } from 'buffer';
|
||||
import { uploadImage } from '../../../providers/esteem/esteem';
|
||||
import { postContent } from '../../../providers/steem/dsteem';
|
||||
import { postContent, getPurePost } from '../../../providers/steem/dsteem';
|
||||
import { setDraftPost, getDraftPost } from '../../../realm/realm';
|
||||
|
||||
// Constants
|
||||
import { default as ROUTES } from '../../../constants/routeNames';
|
||||
// // Constants
|
||||
// import { default as ROUTES } from '../../../constants/routeNames';
|
||||
|
||||
// Utilities
|
||||
import {
|
||||
@ -20,6 +20,7 @@ import {
|
||||
makeOptions,
|
||||
extractMetadata,
|
||||
makeJsonMetadataReply,
|
||||
createPatch,
|
||||
} from '../../../utils/editor';
|
||||
// import { generateSignature } from '../../../utils/image';
|
||||
// Component
|
||||
@ -40,6 +41,7 @@ class EditorContainer extends Component {
|
||||
isCameraOrPickerOpen: false,
|
||||
isDraftSaved: false,
|
||||
isDraftSaving: false,
|
||||
isEdit: false,
|
||||
isPostSending: false,
|
||||
isReply: false,
|
||||
isUploading: false,
|
||||
@ -54,15 +56,33 @@ class EditorContainer extends Component {
|
||||
const { currentAccount, navigation } = this.props;
|
||||
const username = currentAccount && currentAccount.name ? currentAccount.name : '';
|
||||
let isReply;
|
||||
let isEdit;
|
||||
let post;
|
||||
|
||||
if (navigation.state && navigation.state.params) {
|
||||
const navigationParams = navigation.state.params;
|
||||
|
||||
if (navigationParams.post) {
|
||||
post = navigationParams.post;
|
||||
this.setState({ post });
|
||||
}
|
||||
|
||||
if (navigationParams.isReply) {
|
||||
isReply = navigationParams.isReply;
|
||||
post = navigationParams.post;
|
||||
this.setState({ isReply, post });
|
||||
this.setState({ isReply });
|
||||
}
|
||||
|
||||
if (navigationParams.isEdit) {
|
||||
isEdit = navigationParams.isEdit;
|
||||
this.setState(
|
||||
{
|
||||
isEdit,
|
||||
draftPost: { title: post.title, tags: post.json_metadata.tags },
|
||||
},
|
||||
() => {
|
||||
this._getPurePost(post.author, post.permlink);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (navigationParams.action) {
|
||||
@ -72,7 +92,7 @@ class EditorContainer extends Component {
|
||||
this.setState({ autoFocusText: true });
|
||||
}
|
||||
|
||||
if (!isReply) {
|
||||
if (!isReply && !isEdit) {
|
||||
getDraftPost(username)
|
||||
.then((result) => {
|
||||
this.setState({
|
||||
@ -85,6 +105,21 @@ class EditorContainer extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
_getPurePost = (author, permlink) => {
|
||||
getPurePost(author, permlink)
|
||||
.then((result) => {
|
||||
if (result) {
|
||||
this.setState(prevState => ({
|
||||
draftPost: {
|
||||
...prevState.draftPost,
|
||||
body: result.body,
|
||||
},
|
||||
}));
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
_handleRoutingAction = (routingAction) => {
|
||||
this.setState({ isCameraOrPickerOpen: true });
|
||||
|
||||
@ -207,7 +242,7 @@ class EditorContainer extends Component {
|
||||
|
||||
const meta = extractMetadata(fields.body);
|
||||
const jsonMeta = makeJsonMetadata(meta, fields.tags);
|
||||
//TODO: check if permlink is available github: #314 https://github.com/esteemapp/esteem-mobile/pull/314
|
||||
// TODO: check if permlink is available github: #314 https://github.com/esteemapp/esteem-mobile/pull/314
|
||||
const permlink = generatePermlink(fields.title);
|
||||
const author = currentAccount.name;
|
||||
const options = makeOptions(author, permlink);
|
||||
@ -263,7 +298,46 @@ class EditorContainer extends Component {
|
||||
0,
|
||||
)
|
||||
.then((result) => {
|
||||
this._handleReplySuccess();
|
||||
this._handleSubmitSuccess();
|
||||
})
|
||||
.catch((error) => {
|
||||
this._handleSubmitFailure(error);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
_submitEdit = async (fields) => {
|
||||
const { currentAccount, pinCode } = this.props;
|
||||
const { post } = this.state;
|
||||
if (currentAccount) {
|
||||
this.setState({ isPostSending: true });
|
||||
|
||||
const {
|
||||
body: oldBody, parent_permlink: parentPermlink, permlink, parent_author: parentAuthor,
|
||||
} = post;
|
||||
|
||||
let newBody = fields.body;
|
||||
const patch = createPatch(oldBody, newBody.trim());
|
||||
|
||||
if (patch && patch.length < Buffer.from(oldBody, 'utf-8').length) {
|
||||
newBody = patch;
|
||||
}
|
||||
|
||||
const meta = extractMetadata(fields.body);
|
||||
const jsonMeta = makeJsonMetadata(meta, fields.tags);
|
||||
|
||||
await postContent(
|
||||
currentAccount,
|
||||
pinCode,
|
||||
parentAuthor || '',
|
||||
parentPermlink,
|
||||
permlink,
|
||||
fields.title,
|
||||
newBody,
|
||||
jsonMeta,
|
||||
)
|
||||
.then((result) => {
|
||||
this._handleSubmitSuccess();
|
||||
})
|
||||
.catch((error) => {
|
||||
this._handleSubmitFailure(error);
|
||||
@ -276,7 +350,7 @@ class EditorContainer extends Component {
|
||||
this.setState({ isPostSending: false });
|
||||
};
|
||||
|
||||
_handleReplySuccess = () => {
|
||||
_handleSubmitSuccess = () => {
|
||||
const { navigation } = this.props;
|
||||
|
||||
navigation.goBack();
|
||||
@ -284,10 +358,12 @@ class EditorContainer extends Component {
|
||||
};
|
||||
|
||||
_handleSubmit = (form) => {
|
||||
const { isReply } = this.state;
|
||||
const { isReply, isEdit } = this.state;
|
||||
|
||||
if (isReply) {
|
||||
if (isReply && !isEdit) {
|
||||
this._submitReply(form.fields);
|
||||
} else if (isEdit) {
|
||||
this._submitEdit(form.fields);
|
||||
} else {
|
||||
this._submitPost(form.fields);
|
||||
}
|
||||
@ -309,6 +385,7 @@ class EditorContainer extends Component {
|
||||
isCameraOrPickerOpen,
|
||||
isDraftSaved,
|
||||
isDraftSaving,
|
||||
isEdit,
|
||||
isOpenCamera,
|
||||
isPostSending,
|
||||
isReply,
|
||||
@ -333,6 +410,7 @@ class EditorContainer extends Component {
|
||||
isOpenCamera={isOpenCamera}
|
||||
isPostSending={isPostSending}
|
||||
isReply={isReply}
|
||||
isEdit={isEdit}
|
||||
isUploading={isUploading}
|
||||
post={post}
|
||||
uploadedImage={uploadedImage}
|
||||
|
@ -129,14 +129,14 @@ class EditorScreen extends Component {
|
||||
|
||||
render() {
|
||||
const {
|
||||
draftPost, fields, isChanged, isPreviewActive, wordsCount, isFormValid,
|
||||
fields, isPreviewActive, wordsCount, isFormValid,
|
||||
} = this.state;
|
||||
const {
|
||||
autoFocusText,
|
||||
handleOnImagePicker,
|
||||
intl,
|
||||
isDraftSaved,
|
||||
isDraftSaving,
|
||||
isEdit,
|
||||
isLoggedIn,
|
||||
isPostSending,
|
||||
isReply,
|
||||
@ -144,6 +144,9 @@ class EditorScreen extends Component {
|
||||
post,
|
||||
uploadedImage,
|
||||
} = this.props;
|
||||
const rightButtonText = intl.formatMessage({
|
||||
id: isEdit ? 'basic_header.update' : isReply ? 'basic_header.reply' : 'basic_header.publish',
|
||||
});
|
||||
|
||||
return (
|
||||
<View style={globalStyles.defaultContainer}>
|
||||
@ -155,11 +158,13 @@ class EditorScreen extends Component {
|
||||
isDraftSaving={isDraftSaving}
|
||||
isFormValid={isFormValid}
|
||||
isHasIcons
|
||||
isEdit={isEdit}
|
||||
isLoggedIn={isLoggedIn}
|
||||
isReply={isReply}
|
||||
isLoading={isPostSending || isUploading}
|
||||
isPreviewActive={isPreviewActive}
|
||||
quickTitle={wordsCount > 0 && `${wordsCount} words`}
|
||||
rightButtonText={rightButtonText}
|
||||
/>
|
||||
<PostForm
|
||||
handleFormUpdate={this._handleFormUpdate}
|
||||
@ -167,7 +172,7 @@ class EditorScreen extends Component {
|
||||
isFormValid={isFormValid}
|
||||
isPreviewActive={isPreviewActive}
|
||||
>
|
||||
{isReply && <SummaryArea summary={post.summary} />}
|
||||
{isReply && !isEdit && <SummaryArea summary={post.summary} />}
|
||||
{!isReply && <TitleArea value={fields.title} componentID="title" intl={intl} />}
|
||||
{!isReply && (
|
||||
<TagArea
|
||||
|
@ -20,10 +20,9 @@ export const generatePermlink = (title, random = false) => {
|
||||
|
||||
// only letters numbers and dashes
|
||||
perm = perm.toLowerCase().replace(/[^a-z0-9-]+/g, '');
|
||||
return perm;
|
||||
}
|
||||
return perm;
|
||||
}
|
||||
return null;
|
||||
|
||||
};
|
||||
|
||||
export const generateReplyPermlink = (toAuthor) => {
|
||||
|
Loading…
Reference in New Issue
Block a user