Browse Source

refactor: DRY

Tienson Qin 5 years ago
parent
commit
4da72149ee

+ 3 - 6
src/main/frontend/handler/editor.cljs

@@ -546,15 +546,13 @@
              (when (or (seq retract-refs) pre-block?)
                (ui-handler/re-render-root!))
 
-             (when (state/git-auto-push?)
-               (repo-handler/push repo nil)))
+             (repo-handler/push-if-auto-enabled! repo))
 
            :else
            nil))
 
        (seq (state/get-changed-files))
-       (when (state/git-auto-push?)
-         (repo-handler/push repo nil))
+       (repo-handler/push-if-auto-enabled! repo)
 
        :else
        nil))))
@@ -1016,8 +1014,7 @@
           (route-handler/redirect! {:to :page
                                     :path-params {:name (:page/name page)}})
           (ui-handler/re-render-root!))
-        (when (state/git-auto-push?)
-          (repo-handler/push repo nil))))))
+        (repo-handler/push-if-auto-enabled! repo)))))
 
 (defn remove-block-property!
   [block-id key]

+ 2 - 4
src/main/frontend/handler/page.cljs

@@ -257,8 +257,7 @@
                                          file-path)
                                     nil)]
                  (common-handler/check-changed-files-status)
-                 (when (state/git-auto-push?)
-                   (repo-handler/push repo nil)))
+                 (repo-handler/push-if-auto-enabled! repo))
                (p/catch (fn [err]
                           (prn "error: " err))))))
 
@@ -304,8 +303,7 @@
 
         (notification/show! "Page renamed successfully!" :success)
 
-        (when (state/git-auto-push?)
-          (repo-handler/push repo nil))
+        (repo-handler/push-if-auto-enabled! repo)
 
         (ui-handler/re-render-root!)))))
 

+ 5 - 0
src/main/frontend/handler/repo.cljs

@@ -437,6 +437,11 @@
                      (println "Git push error: ")
                      (js/console.dir error)))))))
 
+(defn push-if-auto-enabled!
+  [repo]
+  (when (state/git-auto-push?)
+    (push repo nil)))
+
 (defn pull-current-repo
   []
   (when-let [repo (state/get-current-repo)]