Browse Source

refactor: sync immediately on saving block or drag&drop

Related to https://github.com/logseq/logseq/issues/470
Tienson Qin 5 năm trước cách đây
mục cha
commit
c087143ea4

+ 0 - 7
src/main/frontend/components/file.cljs

@@ -67,13 +67,6 @@
                                    (export-handler/download-file! file))}
                       [:span (tongue :download)]]]]))]]))]))
 
-(defn- save-file!
-  [path content]
-  (fn [value]
-    (when (not= (string/trim value) (string/trim content))
-      (file/alter-file (state/get-current-repo) path (string/trim value)
-                       {:re-render-root? true}))))
-
 (rum/defcs file < rum/reactive
   {:did-mount (fn [state]
                 (state/set-file-component! (:rum/react-component state))

+ 7 - 1
src/main/frontend/handler/dnd.cljs

@@ -2,6 +2,7 @@
   (:require [frontend.handler.notification :as notification]
             [frontend.handler.repo :as repo-handler]
             [frontend.config :as config]
+            [frontend.state :as state]
             [frontend.util :as util :refer-macros [profile]]
             [frontend.db :as db]
             [clojure.walk :as walk]
@@ -508,4 +509,9 @@
 
           ;; different repos
           :else
-          (move-block-in-different-repos target-block-repo to-block-repo target-block to-block top-block bottom-block nested? top? target-child? direction target-content target-file original-top-block-start-pos block-changes))))))
+          (move-block-in-different-repos target-block-repo to-block-repo target-block to-block top-block bottom-block nested? top? target-child? direction target-content target-file original-top-block-start-pos block-changes))
+
+        (when (state/git-auto-push?)
+          (doseq [repo (->> #{target-block-repo to-block-repo}
+                            (remove nil?))]
+            (repo-handler/push repo nil)))))))

+ 4 - 1
src/main/frontend/handler/editor.cljs

@@ -543,7 +543,10 @@
                  [[file-path new-content]])))
 
              (when (or (seq retract-refs) pre-block?)
-               (ui-handler/re-render-root!)))
+               (ui-handler/re-render-root!))
+
+             (when (state/git-auto-push?)
+                 (repo-handler/push repo nil)))
 
            :else
            nil))))))

+ 12 - 9
src/main/frontend/handler/repo.cljs

@@ -318,14 +318,16 @@
          (db/cloned? repo-url)
          token)
     (let [status (db/get-key-value repo-url :git/status)]
-      (when (or
-             force-pull?
-             (and
-              ;; (not= status :push-failed)
-              (not= status :pushing)
-              (empty? (state/get-changed-files repo-url))
-              (not (state/get-edit-input-id))
-              (not (state/in-draw-mode?))))
+      (when (and
+             (not= status :pulling)
+             (or
+              force-pull?
+              (and
+               ;; (not= status :push-failed)
+               (not= status :pushing)
+               (empty? (state/get-changed-files repo-url))
+               (not (state/get-edit-input-id))
+               (not (state/in-draw-mode?)))))
         (git-handler/set-git-status! repo-url :pulling)
         (let [latest-commit (db/get-key-value repo-url :git/latest-commit)]
           (->
@@ -403,7 +405,8 @@
   (let [status (db/get-key-value repo-url :git/status)]
     (when (and
            (db/cloned? repo-url)
-           (not (state/get-edit-input-id)))
+           (not (state/get-edit-input-id))
+           (not= status :pushing))
       (-> (p/let [files (js/window.workerThread.getChangedFiles (util/get-repo-dir (state/get-current-repo)))]
             (when (or
                    ;; FIXME:

+ 4 - 0
src/main/frontend/state.cljs

@@ -834,3 +834,7 @@
   (set-new-block-shortcut!
    (or (get-shortcut repo-url :editor/new-block)
        "enter")))
+
+(defn git-auto-push?
+  []
+  (true? (:git-auto-push (get-config (get-current-repo)))))