Merge pull request #1048 from esteemapp/bugfix/comment-draft

Fixed comment draft issue
This commit is contained in:
uğur erdal 2019-08-14 14:28:09 +03:00 committed by GitHub
commit abe582fd9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 11 deletions

View File

@ -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 = () => {

View File

@ -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 => {