diff --git a/src/screens/editor/container/editorContainer.js b/src/screens/editor/container/editorContainer.js index 11ae91520..7804a4f17 100644 --- a/src/screens/editor/container/editorContainer.js +++ b/src/screens/editor/container/editorContainer.js @@ -269,7 +269,7 @@ class EditorContainer extends Component { }; _saveCurrentDraft = async fields => { - const { draftId, isReply, isEdit } = this.state; + const { draftId, isReply, isEdit, isPostSending } = this.state; if (!draftId && !isEdit) { const { currentAccount } = this.props; @@ -279,11 +279,12 @@ class EditorContainer extends Component { ...fields, tags: fields.tags && fields.tags.length > 0 ? fields.tags.toString() : '', }; - - if (isReply && draftField.body) { - await AsyncStorage.setItem('temp-reply', draftField.body); - } else { - setDraftPost(draftField, username); + if (!isPostSending) { + if (isReply && draftField.body) { + await AsyncStorage.setItem('temp-reply', draftField.body); + } else { + setDraftPost(draftField, username); + } } } }; @@ -451,6 +452,7 @@ class EditorContainer extends Component { jsonMeta, ) .then(() => { + AsyncStorage.setItem('temp-reply', ''); this._handleSubmitSuccess(); }) .catch(error => { @@ -468,7 +470,10 @@ class EditorContainer extends Component { }), error.message || error.toString(), ); - this.setState({ isPostSending: false }); + this.stateTimer = setTimeout(() => { + this.setState({ isPostSending: false }); + clearTimeout(this.stateTimer); + }, 500); }; _handleSubmitSuccess = () => { @@ -479,7 +484,10 @@ class EditorContainer extends Component { navigation.state.params.fetchPost(); } - this.setState({ isPostSending: false }); + this.stateTimer = setTimeout(() => { + this.setState({ isPostSending: false }); + clearTimeout(this.stateTimer); + }, 500); }; _handleOnBackPress = () => { diff --git a/src/screens/editor/screen/editorScreen.js b/src/screens/editor/screen/editorScreen.js index 72212bf07..0544bb339 100644 --- a/src/screens/editor/screen/editorScreen.js +++ b/src/screens/editor/screen/editorScreen.js @@ -93,9 +93,8 @@ class EditorScreen extends Component { saveDraftToDB(fields); }; - _saveCurrentDraft = () => { + _saveCurrentDraft = fields => { const { saveCurrentDraft } = this.props; - const { fields } = this.state; if (this.changeTimer) { clearTimeout(this.changeTimer); @@ -149,12 +148,12 @@ class EditorScreen extends Component { get(fields, 'tags') !== get(_fields, 'tags') ) { handleFormChanged(); + this._saveCurrentDraft(fields); } this.setState({ fields }); this._handleIsFormValid(); - this._saveCurrentDraft(); }; _handleOnTagAdded = async tags => {