Просмотр исходного кода

change timing conditional branch whether this page is first

yusuketk 6 лет назад
Родитель
Сommit
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.setState({ markdown: value });
     }));
-    this.saveDraftWithDebounce = debounce(800, this.saveDraft);
+    this.saveDraftWithDebounce = debounce(3000, this.saveDraft);
   }
 
   componentWillMount() {
@@ -89,8 +89,13 @@ class PageEditor extends React.Component {
    * @param {string} value
    */
   onMarkdownChanged(value) {
+    const { pageContainer, editorContainer } = this.props;
     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() {
     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() {

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

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