Browse Source

fix(sync): push immediately after the page was deleted or renamed

Tienson Qin 5 years ago
parent
commit
3197b784fd
3 changed files with 34 additions and 18 deletions
  1. 1 1
      resources/index.html
  2. 26 16
      src/main/frontend/handler/editor.cljs
  3. 7 1
      src/main/frontend/handler/page.cljs

+ 1 - 1
resources/index.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html><head><meta charset="utf-8"><meta content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no" name="viewport"><meta content="Agp2znmEoRKqxMhzbNL2R3UOCNcagP7+fu0KSM+09O21u7EHdJgqhTrslpfyFC/dSt6jvpaDzNiFf2769fLHMAUAAABoeyJvcmlnaW4iOiJodHRwczovL2xvZ3NlcS5jb206NDQzIiwiZmVhdHVyZSI6Ik5hdGl2ZUZpbGVTeXN0ZW0yIiwiZXhwaXJ5IjoxNTk3Mjg5MzY5LCJpc1N1YmRvbWFpbiI6dHJ1ZX0=" http-equiv="origin-trial"><link href="https://asset.logseq.com/static/style.css" rel="stylesheet" type="text/css"><link href="https://asset.logseq.com/static/img/logo.png" rel="shortcut icon" type="image/png"><link href="https://asset.logseq.com/static/img/logo.png" rel="shortcut icon" sizes="192x192"><link href="https://asset.logseq.com/static/img/logo.png" rel="apple-touch-icon"><meta content="summary" name="twitter:card"><meta content="A local-first notes app which uses Git to store and sync your knowledge." name="twitter:description"><meta content="@logseq" name="twitter:site"><meta content="A local-first notes app." name="twitter:title"><meta content="https://asset.logseq.com/static/img/logo.png" name="twitter:image:src"><meta content="A local-first notes app." name="twitter:image:alt"><meta content="A local-first notes app." property="og:title"><meta content="site" property="og:type"><meta content="https://logseq.com" property="og:url"><meta content="https://asset.logseq.com/static/img/logo.png" property="og:image"><meta content="A local-first notes app which uses Git to store and sync your knowledge." property="og:description"><title>Logseq: A local-first notes app</title><meta content="logseq" property="og:site_name"><meta description="A local-first notes app which uses Git to store and sync your knowledge."><script crossorigin="anonymous" defer onload="if (window.location.host != &apos;localhost:3000&apos;) {
           Sentry.init({dsn: &apos;https://[email protected]/5311485&apos;});
-};" src="https://asset.logseq.com/static/js/sentry.min.js"></script></head><body><div id="root"></div><script>window.user={"name":"tiensonqin","email":"[email protected]","avatar":"https://avatars3.githubusercontent.com/u/479169?v=4","repos":[{"id":"bc80efff-1420-4eb7-9e07-9506b8d9bbe0","url":"https://github.com/tiensonqin/notes"}],"preferred_format":"org","encrypt_object_key":"snRsaP8r9VG6KsXxu0IfDA"};</script><script src="https://asset.logseq.com/static/js/mldoc.min.js"></script><script src="https://asset.logseq.com/static/js/magic_portal.js"></script><script>let worker = new Worker("/static/js/worker.js");
+};" src="https://asset.logseq.com/static/js/sentry.min.js"></script></head><body><div id="root"></div><script>window.user={"name":"tiensonqin","email":"[email protected]","avatar":"https://avatars3.githubusercontent.com/u/479169?v=4","repos":[{"id":"bc80efff-1420-4eb7-9e07-9506b8d9bbe0","url":"https://github.com/tiensonqin/notes"}],"preferred_format":"org","encrypt_object_key":"snRsaP8r9VG6KsXxu0IfDA"};</script><script src="https://asset.logseq.com/static/js/mldoc.min.js"></script><script src="/js/magic_portal.js"></script><script>let worker = new Worker("/js/worker.js");
 const portal = new MagicPortal(worker);
 ;(async () => {
   const git = await portal.get('git');

+ 26 - 16
src/main/frontend/handler/editor.cljs

@@ -283,8 +283,8 @@
                                 (reset! last-child-end-pos old-end-pos)))
 
                             (cond->
-                             {:block/uuid uuid
-                              :block/meta new-meta}
+                                {:block/uuid uuid
+                                 :block/meta new-meta}
                               (and (some? indent-left?) (not @next-leq-level?))
                               (assoc :block/level (if indent-left? (dec level) (inc level)))
                               (and new-content (not @next-leq-level?))
@@ -401,9 +401,9 @@
                      (util/->tags tags))
          page-alias (when-let [alias (:alias new-properties)]
                       (map
-                       (fn [alias]
-                         {:page/name (string/lower-case alias)})
-                       (remove #{(:page/name page)} alias)))
+                        (fn [alias]
+                          {:page/name (string/lower-case alias)})
+                        (remove #{(:page/name page)} alias)))
          permalink-changed? (when (and pre-block? (:permalink old-properties))
                               (not= (:permalink old-properties)
                                     (:permalink new-properties)))
@@ -423,7 +423,8 @@
 
                  :else
                  value)]
-     (when (not= (string/trim content) (string/trim value)) ; block content changed
+     (cond
+       (not= (string/trim content) (string/trim value)) ; block content changed
        (let [file (db/entity repo (:db/id file))]
          (cond
            ;; Page was referenced but no related file
@@ -505,10 +506,10 @@
                                      [[:db/retract page-id :page/properties]]))
                  pages (if (seq page-tags)
                          (let [tag-pages (map
-                                          (fn [page]
-                                            {:page/original-name page
-                                             :page/name page})
-                                          (map :tag/name page-tags))]
+                                           (fn [page]
+                                             {:page/original-name page
+                                              :page/name page})
+                                           (map :tag/name page-tags))]
                            (concat pages tag-pages))
                          pages)
                  page-tags (when (and pre-block? (seq page-tags))
@@ -546,10 +547,17 @@
                (ui-handler/re-render-root!))
 
              (when (state/git-auto-push?)
-                 (repo-handler/push repo nil)))
+               (repo-handler/push repo nil)))
 
            :else
-           nil))))))
+           nil))
+
+       (seq (state/get-changed-files))
+       (when (state/git-auto-push?)
+         (repo-handler/push repo nil))
+
+       :else
+       nil))))
 
 (defn insert-new-block-aux!
   [{:block/keys [uuid content meta file dummy? level repo page format properties collapsed?] :as block}
@@ -1007,7 +1015,9 @@
         (when top-block?
           (route-handler/redirect! {:to :page
                                     :path-params {:name (:page/name page)}})
-          (ui-handler/re-render-root!))))))
+          (ui-handler/re-render-root!))
+        (when (state/git-auto-push?)
+          (repo-handler/push repo nil))))))
 
 (defn remove-block-property!
   [block-id key]
@@ -1099,7 +1109,7 @@
   ;; (when e
   ;;   (when-not (util/input? (gobj/get e "target"))
   ;;     (util/clear-selection!)))
-)
+  )
 
 (defn clear-selection-blocks!
   []
@@ -1751,7 +1761,7 @@
                                                                 :end-pos end-pos}))]
                                  (reset! last-start-pos end-pos)
                                  block))
-                             blocks))
+                          blocks))
                 file-id (:db/id (:block/file block))
                 file (db/entity file-id)
                 page (:block/page block)
@@ -1815,7 +1825,7 @@
                                                               :end-pos end-pos}))]
                                (reset! last-start-pos end-pos)
                                block))
-                           blocks))
+                        blocks))
               file-id (:db/id (:block/file block))
               file (db/entity file-id)
               page (:block/page block)

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

@@ -9,6 +9,7 @@
             [frontend.handler.common :as common-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.file :as file-handler]
+            [frontend.handler.repo :as repo-handler]
             [frontend.handler.git :as git-handler]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.project :as project-handler]
@@ -255,7 +256,9 @@
                                          "/"
                                          file-path)
                                     nil)]
-                 (common-handler/check-changed-files-status))
+                 (common-handler/check-changed-files-status)
+                 (when (state/git-auto-push?)
+                   (repo-handler/push repo nil)))
                (p/catch (fn [err]
                           (prn "error: " err))))))
 
@@ -301,6 +304,9 @@
 
         (notification/show! "Page renamed successfully!" :success)
 
+        (when (state/git-auto-push?)
+          (repo-handler/push repo nil))
+
         (ui-handler/re-render-root!)))))
 
 (defn rename-when-alter-title-propertiy!