updated for remove reply

This commit is contained in:
u-e 2019-02-14 11:41:58 +03:00
parent d4f7911437
commit 29830ee54f

View File

@ -118,7 +118,7 @@ class EditorContainer extends Component {
}); });
} else { } else {
await getDraftPost(username) await getDraftPost(username)
.then((result) => { .then(result => {
this.setState({ this.setState({
draftPost: { body: result.body, title: result.title, tags: result.tags.split(',') }, draftPost: { body: result.body, title: result.title, tags: result.tags.split(',') },
}); });
@ -127,13 +127,11 @@ class EditorContainer extends Component {
// alert(error); // alert(error);
}); });
} }
}; };
_getPurePost = (author, permlink) => { _getPurePost = (author, permlink) => {
getPurePost(author, permlink) getPurePost(author, permlink)
.then((result) => { .then(result => {
if (result) { if (result) {
this.setState(prevState => ({ this.setState(prevState => ({
draftPost: { draftPost: {
@ -146,7 +144,7 @@ class EditorContainer extends Component {
.catch(() => {}); .catch(() => {});
}; };
_handleRoutingAction = (routingAction) => { _handleRoutingAction = routingAction => {
this.setState({ isCameraOrPickerOpen: true }); this.setState({ isCameraOrPickerOpen: true });
if (routingAction === 'camera') { if (routingAction === 'camera') {
@ -162,10 +160,10 @@ class EditorContainer extends Component {
ImagePicker.openPicker({ ImagePicker.openPicker({
includeBase64: true, includeBase64: true,
}) })
.then((image) => { .then(image => {
this._handleMediaOnSelected(image); this._handleMediaOnSelected(image);
}) })
.catch((e) => { .catch(e => {
this._handleMediaOnSelectFailure(e); this._handleMediaOnSelectFailure(e);
}); });
}; };
@ -174,15 +172,15 @@ class EditorContainer extends Component {
ImagePicker.openCamera({ ImagePicker.openCamera({
includeBase64: true, includeBase64: true,
}) })
.then((image) => { .then(image => {
this._handleMediaOnSelected(image); this._handleMediaOnSelected(image);
}) })
.catch((e) => { .catch(e => {
this._handleMediaOnSelectFailure(e); this._handleMediaOnSelectFailure(e);
}); });
}; };
_handleMediaOnSelected = (media) => { _handleMediaOnSelected = media => {
this.setState({ isCameraOrPickerOpen: false, isUploading: true }, () => { this.setState({ isCameraOrPickerOpen: false, isUploading: true }, () => {
this._uploadImage(media); this._uploadImage(media);
}); });
@ -194,7 +192,7 @@ class EditorContainer extends Component {
// const data = new Buffer(media.data, 'base64'); // const data = new Buffer(media.data, 'base64');
}; };
_uploadImage = (media) => { _uploadImage = media => {
const { intl } = this.props; const { intl } = this.props;
const file = { const file = {
@ -205,12 +203,12 @@ class EditorContainer extends Component {
}; };
uploadImage(file) uploadImage(file)
.then((res) => { .then(res => {
if (res.data && res.data.url) { if (res.data && res.data.url) {
this.setState({ uploadedImage: res.data, isUploading: false }); this.setState({ uploadedImage: res.data, isUploading: false });
} }
}) })
.catch((error) => { .catch(error => {
Alert.alert( Alert.alert(
intl.formatMessage({ intl.formatMessage({
id: 'alert.fail', id: 'alert.fail',
@ -221,7 +219,7 @@ class EditorContainer extends Component {
}); });
}; };
_handleMediaOnSelectFailure = (error) => { _handleMediaOnSelectFailure = error => {
const { intl } = this.props; const { intl } = this.props;
this.setState({ isCameraOrPickerOpen: false }); this.setState({ isCameraOrPickerOpen: false });
@ -239,7 +237,7 @@ class EditorContainer extends Component {
// Media select functions <- END -> // Media select functions <- END ->
_saveDraftToDB = (fields) => { _saveDraftToDB = fields => {
const { isDraftSaved, draftId } = this.state; const { isDraftSaved, draftId } = this.state;
if (!isDraftSaved) { if (!isDraftSaved) {
const { currentAccount } = this.props; const { currentAccount } = this.props;
@ -259,7 +257,7 @@ class EditorContainer extends Component {
}); });
}); });
} else { } else {
addDraft(draftField).then((response) => { addDraft(draftField).then(response => {
this.setState({ this.setState({
isDraftSaved: true, isDraftSaved: true,
draftId: response._id, draftId: response._id,
@ -273,7 +271,7 @@ class EditorContainer extends Component {
} }
}; };
_saveCurrentDraft = async (fields) => { _saveCurrentDraft = async fields => {
const { draftId, isReply } = this.state; const { draftId, isReply } = this.state;
if (!draftId) { if (!draftId) {
@ -293,10 +291,8 @@ class EditorContainer extends Component {
} }
}; };
_submitPost = async (fields) => { _submitPost = async fields => {
const { const { navigation, currentAccount, pinCode, intl } = this.props;
navigation, currentAccount, pinCode, intl,
} = this.props;
if (currentAccount) { if (currentAccount) {
this.setState({ isPostSending: true }); this.setState({ isPostSending: true });
@ -355,13 +351,13 @@ class EditorContainer extends Component {
setDraftPost({ title: '', body: '', tags: [] }, currentAccount.name); setDraftPost({ title: '', body: '', tags: [] }, currentAccount.name);
}) })
.catch((error) => { .catch(error => {
this._handleSubmitFailure(error); this._handleSubmitFailure(error);
}); });
} }
}; };
_submitReply = async (fields) => { _submitReply = async fields => {
const { currentAccount, pinCode } = this.props; const { currentAccount, pinCode } = this.props;
if (currentAccount) { if (currentAccount) {
@ -390,14 +386,15 @@ class EditorContainer extends Component {
) )
.then(() => { .then(() => {
this._handleSubmitSuccess(); this._handleSubmitSuccess();
AsyncStorage.setItem('temp-reply', "");
}) })
.catch((error) => { .catch(error => {
this._handleSubmitFailure(error); this._handleSubmitFailure(error);
}); });
} }
}; };
_submitEdit = async (fields) => { _submitEdit = async fields => {
const { currentAccount, pinCode } = this.props; const { currentAccount, pinCode } = this.props;
const { post } = this.state; const { post } = this.state;
if (currentAccount) { if (currentAccount) {
@ -435,13 +432,13 @@ class EditorContainer extends Component {
.then(() => { .then(() => {
this._handleSubmitSuccess(); this._handleSubmitSuccess();
}) })
.catch((error) => { .catch(error => {
this._handleSubmitFailure(error); this._handleSubmitFailure(error);
}); });
} }
}; };
_handleSubmitFailure = (error) => { _handleSubmitFailure = error => {
const { intl } = this.props; const { intl } = this.props;
Alert.alert( Alert.alert(
@ -469,7 +466,7 @@ class EditorContainer extends Component {
} }
}; };
_handleSubmit = (form) => { _handleSubmit = form => {
const { isReply, isEdit } = this.state; const { isReply, isEdit } = this.state;
if (isReply && !isEdit) { if (isReply && !isEdit) {