saving local draft only when editor exits or remote draft save fails

This commit is contained in:
Nouman Tahir 2022-07-21 15:54:24 +05:00
parent fb973b9a46
commit 6ab79306c7
2 changed files with 16 additions and 13 deletions

View File

@ -55,6 +55,7 @@ import { deleteDraftCacheEntry, updateCommentCache, updateDraftCache } from '../
class EditorContainer extends Component<any, any> {
_isMounted = false;
_updatedDraftFields = null;
constructor(props) {
super(props);
@ -571,10 +572,9 @@ class EditorContainer extends Component<any, any> {
const { isDraftSaved, draftId, thumbIndex, isReply, rewardType } = this.state;
const { currentAccount, dispatch, intl } = this.props;
//Saves draft locally for both reply and post
this._saveCurrentDraft(fields)
if (isReply) {
this._saveCurrentDraft(this._updatedDraftFields)
return;
}
@ -658,6 +658,9 @@ class EditorContainer extends Component<any, any> {
isDraftSaving: false,
isDraftSaved: false,
});
//saves draft locally if remote draft save fails
this._saveCurrentDraft(this._updatedDraftFields)
}
dispatch(
@ -671,6 +674,10 @@ class EditorContainer extends Component<any, any> {
};
_updateDraftFields = (fields) => {
this._updatedDraftFields = fields;
}
_saveCurrentDraft = async (fields) => {
const { draftId, isReply, isEdit, isPostSending } = this.state;
@ -1294,6 +1301,7 @@ class EditorContainer extends Component<any, any> {
quickReplyText={quickReplyText}
isUploading={isUploading}
post={post}
updateDraftFields = {this._updateDraftFields}
saveCurrentDraft={this._saveCurrentDraft}
saveDraftToDB={this._saveDraftToDB}
uploadedImage={uploadedImage}
@ -1309,6 +1317,7 @@ class EditorContainer extends Component<any, any> {
rewardType={rewardType}
scheduledForDate={scheduledForDate}
getBeneficiaries={this._extractBeneficiaries}
/>
);
}

View File

@ -9,17 +9,11 @@ import { extractMetadata, getWordsCount, makeJsonMetadata } from '../../../utils
// Components
import {
BasicHeader,
TitleArea,
TagArea,
TagInput,
SummaryArea,
PostForm,
MarkdownEditor,
SelectCommunityAreaView,
SelectCommunityModalContainer,
Modal,
UserAvatar,
MainButton,
} from '../../../components';
// dhive
@ -31,7 +25,6 @@ import globalStyles from '../../../globalStyles';
import { isCommunity } from '../../../utils/communityValidation';
import styles from './editorScreenStyles';
import ThumbSelectionModal from '../children/thumbSelectionModal';
import PostOptionsModal from '../children/postOptionsModal';
class EditorScreen extends Component {
@ -176,14 +169,15 @@ class EditorScreen extends Component {
};
_saveCurrentDraft = (fields) => {
const { saveCurrentDraft } = this.props;
const { saveCurrentDraft, updateDraftFields } = this.props;
if (this.changeTimer) {
clearTimeout(this.changeTimer);
}
this.changeTimer = setTimeout(() => {
saveCurrentDraft(fields);
// saveCurrentDraft(fields);
updateDraftFields(fields)
}, 300);
};
@ -276,8 +270,8 @@ class EditorScreen extends Component {
) {
console.log('jsonMeta : ', jsonMeta);
handleFormChanged();
//TODO: REMOVED FOR TESTING, CAN BE PUT BACK IF APP STILL CRASHES
// this._saveCurrentDraft(fields);
this._saveCurrentDraft(fields);
}
this.setState({ fields }, () => {