diff --git a/src/screens/editor/container/editorContainer.js b/src/screens/editor/container/editorContainer.js index d1f1d10fc..e19e7c03e 100644 --- a/src/screens/editor/container/editorContainer.js +++ b/src/screens/editor/container/editorContainer.js @@ -213,6 +213,31 @@ class EditorContainer extends Component { // Media select functions <- END -> _handleOnSaveButtonPress = (fields) => { + // const { isDraftSaved } = this.state; + // if (!isDraftSaved) { + // const { currentAccount } = this.props; + // const username = currentAccount && currentAccount.name ? currentAccount.name : ''; + + // this.setState({ isDraftSaving: true }); + // const draftField = { + // ...fields, + // tags: fields.tags.toString(), + // }; + + // setDraftPost(draftField, username) + // .then(() => { + // this.setState({ + // isDraftSaving: false, + // isDraftSaved: true, + // }); + // }) + // .catch((error) => { + // alert(error); + // }); + // } + }; + + _saveCurrentDraft = (fields) => { const { isDraftSaved } = this.state; if (!isDraftSaved) { const { currentAccount } = this.props; @@ -391,7 +416,7 @@ class EditorContainer extends Component { } }; - _handleOnPressBackButton= () =>{ + _handleOnPressBackButton= () => { alert("pressed"); } @@ -418,21 +443,22 @@ class EditorContainer extends Component { draftPost={draftPost} handleFormChanged={this._handleFormChanged} handleOnImagePicker={this._handleRoutingAction} + handleOnPressBackButton={this._handleOnPressBackButton} handleOnSaveButtonPress={this._handleOnSaveButtonPress} handleOnSubmit={this._handleSubmit} isCameraOrPickerOpen={isCameraOrPickerOpen} isDarkTheme={isDarkTheme} isDraftSaved={isDraftSaved} isDraftSaving={isDraftSaving} + isEdit={isEdit} isLoggedIn={isLoggedIn} isOpenCamera={isOpenCamera} isPostSending={isPostSending} isReply={isReply} - isEdit={isEdit} isUploading={isUploading} post={post} + saveCurrentDraft={this._saveCurrentDraft} uploadedImage={uploadedImage} - handleOnPressBackButton={this._handleOnPressBackButton} /> ); } diff --git a/src/screens/editor/screen/editorScreen.js b/src/screens/editor/screen/editorScreen.js index 1cbb416b9..7b1cde41a 100644 --- a/src/screens/editor/screen/editorScreen.js +++ b/src/screens/editor/screen/editorScreen.js @@ -74,6 +74,19 @@ class EditorScreen extends Component { handleOnSaveButtonPress(fields); }; + _saveCurrentDraft = () => { + const { saveCurrentDraft } = this.props; + const { fields } = this.state; + + if (this.changeTimer) { + clearTimeout(this.changeTimer); + } + + this.changeTimer = setTimeout(() => { + saveCurrentDraft(fields); + }, 300); + }; + _handleOnSubmit = () => { const { handleOnSubmit } = this.props; const { fields } = this.state; @@ -117,6 +130,7 @@ class EditorScreen extends Component { handleFormChanged(); this._handleIsFormValid(); + this._saveCurrentDraft(); }; _handleOnTagAdded = (tags) => { @@ -147,7 +161,7 @@ class EditorScreen extends Component { handleOnPressBackButton, } = this.props; const rightButtonText = intl.formatMessage({ - id: isEdit ? 'basic_header.update' : isReply ? 'basic_header.reply' : 'basic_header.publish', + id: isEdit ? 'basic_header.update' : isReply ? 'basic_header.reply' : 'basic_header.publish', }); return (