Browse Source

fix: don't auto-save for page's properties block

If the block has a title property. It's to prevent any page
modification while the user is adding or changing the block property.
Tienson Qin 4 years ago
parent
commit
986877b3f5
2 changed files with 25 additions and 18 deletions
  1. 13 8
      src/main/frontend/handler/editor.cljs
  2. 12 10
      src/main/frontend/modules/outliner/file.cljs

+ 13 - 8
src/main/frontend/handler/editor.cljs

@@ -1899,14 +1899,19 @@
     (when @*auto-save-timeout
       (js/clearTimeout @*auto-save-timeout))
     (mark-last-input-time! repo)
-    (reset! *auto-save-timeout
-            (js/setTimeout
-             (fn []
-               (when (state/input-idle? repo)
-                 (state/set-editor-op! :auto-save)
-                 (save-current-block! {})
-                 (state/set-editor-op! nil)))
-             500))))
+    (when-not
+        (and
+         (= (:db/id (:block/parent block))
+            (:db/id (:block/page block)))            ; don't auto-save for page's properties block
+         (get-in block [:block/properties :title]))
+      (reset! *auto-save-timeout
+              (js/setTimeout
+               (fn []
+                 (when (state/input-idle? repo)
+                   (state/set-editor-op! :auto-save)
+                   (save-current-block! {})
+                   (state/set-editor-op! nil)))
+               500)))))
 
 (defn handle-last-input []
   (let [input           (state/get-input)

+ 12 - 10
src/main/frontend/modules/outliner/file.cljs

@@ -30,19 +30,21 @@
 
 (defn write-files!
   [page-db-ids]
-  (when-not config/publishing?
-    (doseq [page-db-id (set page-db-ids)]
-      (try (do-write-file! page-db-id)
-           (catch js/Error e
-             (notification/show!
-              "Write file failed, please copy the changes to other editors in case of losing data."
-              [:div "Error: " (str (gobj/get e "stack"))]
-              :error)
-             (log/error :file/write-file-error {:error e}))))))
+  (when (seq page-db-ids)
+    (when-not config/publishing?
+      (doseq [page-db-id (set page-db-ids)]
+        (try (do-write-file! page-db-id)
+             (catch js/Error e
+               (notification/show!
+                "Write file failed, please copy the changes to other editors in case of losing data."
+                [:div "Error: " (str (gobj/get e "stack"))]
+                :error)
+               (log/error :file/write-file-error {:error e})))))))
 
 (defn sync-to-file
   [{page-db-id :db/id}]
-  (async/put! write-chan page-db-id))
+  (when page-db-id
+    (async/put! write-chan page-db-id)))
 
 (util/batch write-chan
             batch-write-interval