Parcourir la source

fix: git clone every time when refreshing the page

Resolved #787 #333
Tienson Qin il y a 5 ans
Parent
commit
c1b70ae12a

+ 1 - 1
src/main/frontend/db.cljs

@@ -1892,7 +1892,7 @@
 )
                  (let [job (get persistent-jobs repo)]
                    (persist-if-idle! repo))))
-             5000)]
+             3000)]
     (swap! persistent-jobs assoc repo job)))
 
 ;; only save when user's idle

+ 6 - 3
src/main/frontend/fs.cljs

@@ -174,7 +174,10 @@
 (defn stat
   [dir path]
   (let [append-path (if path
-                      (str "/" (string/replace-first path "/" ""))
+                      (str "/"
+                           (if (= \/ (first path))
+                             (subs path 1)
+                             path))
                       "")]
     (cond
       (local-db? dir)
@@ -189,8 +192,8 @@
         (p/rejected "File not exists"))
 
       :else
-     ;; FIXME: same format
-      (js/window.pfs.stat (str dir append-path)))))
+      (do
+        (js/window.pfs.stat (str dir append-path))))))
 
 (defn mkdir-if-not-exists
   [dir]

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

@@ -1981,7 +1981,7 @@
 
 (defn periodically-save!
   []
-  (js/setInterval save-current-block-when-idle! 5000))
+  (js/setInterval save-current-block-when-idle! 3000))
 
 (defn get-current-input-value
   []

+ 0 - 1
src/main/frontend/handler/git.cljs

@@ -1,5 +1,4 @@
 (ns frontend.handler.git
-  (:refer-clojure :exclude [clone load-file])
   (:require [frontend.util :as util :refer-macros [profile]]
             [promesa.core :as p]
             [frontend.state :as state]

+ 3 - 1
src/main/frontend/handler/route.cljs

@@ -79,7 +79,9 @@
   (let [{:keys [data path-params]} route
         title (get-title (:name data) path-params)]
     (util/set-title! title)
-    (ui-handler/scroll-and-highlight! nil)))
+    (if-let [fragment (util/get-fragment)]
+      (ui-handler/highlight-element! fragment)
+      (util/scroll-to-top))))
 
 (defn go-to-search!
   []

+ 1 - 2
src/main/frontend/handler/ui.cljs

@@ -70,8 +70,7 @@
 (defn scroll-and-highlight!
   [state]
   (if-let [fragment (util/get-fragment)]
-    (highlight-element! fragment)
-    (util/scroll-to-top))
+    (highlight-element! fragment))
   state)
 
 (defn add-style-if-exists!

+ 6 - 6
src/main/frontend/mixins.cljs

@@ -61,16 +61,16 @@
                  ;; If the click target is outside of current node
                   (when-not (dom/contains dom-node (.. e -target))
                     (on-hide state e :click))))
-        (when visibilitychange?
-          (listen state js/window "visibilitychange"
-                  (fn [e]
-                    (on-hide state e :visibilitychange))))
-        (listen state dom-node "keydown"
+        (listen state js/window "keydown"
                 (fn [e]
                   (case (.-keyCode e)
                     ;; Esc
                     27 (on-hide state e :esc)
-                    nil)))))
+                    nil)))
+        (when visibilitychange?
+          (listen state js/window "visibilitychange"
+                  (fn [e]
+                    (on-hide state e :visibilitychange))))))
     (catch js/Error e
       ;; TODO: Unable to find node on an unmounted component.
       nil)))

+ 2 - 2
src/main/frontend/state.cljs

@@ -909,7 +909,7 @@
   (when repo
     (when-let [last-time (get-in @state [:db/last-transact-time repo])]
       (let [now (util/time-ms)]
-        (>= (- now last-time) 5000)))))
+        (>= (- now last-time) 3000)))))
 
 (defn input-idle?
   [repo]
@@ -917,7 +917,7 @@
     (or
      (when-let [last-time (get-in @state [:editor/last-input-time repo])]
        (let [now (util/time-ms)]
-         (>= (- now last-time) 5000)))
+         (>= (- now last-time) 3000)))
      ;; not in editing mode
      (not (get-edit-input-id)))))