Explorar el Código

change timing conditional branch whether this page is first

yusuketk hace 6 años
padre
commit
310d7b129d

+ 8 - 7
src/client/js/components/PageEditor.jsx

@@ -56,7 +56,7 @@ class PageEditor extends React.Component {
     this.setMarkdownStateWithDebounce = debounce(50, throttle(100, (value) => {
     this.setMarkdownStateWithDebounce = debounce(50, throttle(100, (value) => {
       this.setState({ markdown: value });
       this.setState({ markdown: value });
     }));
     }));
-    this.saveDraftWithDebounce = debounce(800, this.saveDraft);
+    this.saveDraftWithDebounce = debounce(3000, this.saveDraft);
   }
   }
 
 
   componentWillMount() {
   componentWillMount() {
@@ -89,8 +89,13 @@ class PageEditor extends React.Component {
    * @param {string} value
    * @param {string} value
    */
    */
   onMarkdownChanged(value) {
   onMarkdownChanged(value) {
+    const { pageContainer, editorContainer } = this.props;
     this.setMarkdownStateWithDebounce(value);
     this.setMarkdownStateWithDebounce(value);
-    this.saveDraftWithDebounce();
+    // only when the first time to edit
+    if (!pageContainer.state.revisionId) {
+      this.saveDraftWithDebounce();
+    }
+    editorContainer.enableUnsavedWarning();
   }
   }
 
 
   /**
   /**
@@ -270,11 +275,7 @@ class PageEditor extends React.Component {
 
 
   saveDraft() {
   saveDraft() {
     const { pageContainer, editorContainer } = this.props;
     const { pageContainer, editorContainer } = this.props;
-    // only when the first time to edit
-    if (!pageContainer.state.revisionId) {
-      editorContainer.saveDraft(pageContainer.state.path, this.state.markdown);
-    }
-    editorContainer.enableUnsavedWarning();
+    editorContainer.saveDraft(pageContainer.state.path, this.state.markdown);
   }
   }
 
 
   clearDraft() {
   clearDraft() {

+ 1 - 0
src/client/js/services/EditorContainer.js

@@ -155,6 +155,7 @@ export default class EditorContainer extends Container {
   }
   }
 
 
   disableUnsavedWarning() {
   disableUnsavedWarning() {
+    console.log('AAA');
     window.removeEventListener('beforeunload', this.showUnsavedWarning);
     window.removeEventListener('beforeunload', this.showUnsavedWarning);
     this.isSetBeforeunloadEventHandler = false;
     this.isSetBeforeunloadEventHandler = false;
   }
   }