Browse Source

fix: re-index parsing progress

Tienson Qin 3 years ago
parent
commit
0cfde82909

+ 46 - 41
src/main/frontend/components/sidebar.cljs

@@ -327,22 +327,19 @@
 (defonce sidebar-inited? (atom false))
 ;; TODO: simplify logic
 
-(rum/defc parsing-state < rum/reactive
-  [current-repo]
-  (let [full-state (state/sub [:graph/parsing-state])
-        parsing-state (state/sub [:graph/parsing-state current-repo])]
-    (when (not= (:total parsing-state) (:finished parsing-state))
-     (let [finished (or (:finished parsing-state) 0)
-           total (:total parsing-state)
-           width (js/Math.round (* (.toFixed (/ finished total) 2) 100))
-           left-label [:div.flex.flex-row.font-bold
-                       (t :parsing-files)
-                       [:div.hidden.md:flex.flex-row
-                        [:span.mr-1 ": "]
-                        [:div.text-ellipsis-wrapper {:style {:max-width 300}}
-                         (util/node-path.basename
-                          (:current-parsing-file parsing-state))]]]]
-       (ui/progress-bar-with-label width left-label (str finished "/" total))))))
+(rum/defc parsing-progress < rum/static
+  [state]
+  (let [finished (or (:finished state) 0)
+        total (:total state)
+        width (js/Math.round (* (.toFixed (/ finished total) 2) 100))
+        left-label [:div.flex.flex-row.font-bold
+                    (t :parsing-files)
+                    [:div.hidden.md:flex.flex-row
+                     [:span.mr-1 ": "]
+                     [:div.text-ellipsis-wrapper {:style {:max-width 300}}
+                      (util/node-path.basename
+                       (:current-parsing-file state))]]]]
+    (ui/progress-bar-with-label width left-label (str finished "/" total))))
 
 (rum/defc main-content < rum/reactive db-mixins/query
   {:init (fn [state]
@@ -366,31 +363,39 @@
         current-repo (state/sub :git/current-repo)
         loading-files? (when current-repo (state/sub [:repo/loading-files? current-repo]))
         journals-length (state/sub :journals-length)
-        latest-journals (db/get-latest-journals (state/get-current-repo) journals-length)]
-    [:div
-     (parsing-state current-repo)
-
-     (cond
-       (and default-home
-            (= :home (state/get-current-route))
-            (not (state/route-has-p?))
-            (:page default-home))
-       (route-handler/redirect-to-page! (:page default-home))
-
-       (and config/publishing?
-            (not default-home)
-            (empty? latest-journals))
-       (route-handler/redirect! {:to :all-pages})
-
-       loading-files?
-       (ui/loading (t :loading-files))
-
-       (seq latest-journals)
-       (journal/journals latest-journals)
-
-       ;; FIXME: why will this happen?
-       :else
-       [:div])]))
+        latest-journals (db/get-latest-journals (state/get-current-repo) journals-length)
+        graph-parsing-state (state/sub [:graph/parsing-state current-repo])]
+    (cond
+      (or
+       (:graph-loading? graph-parsing-state)
+       (not= (:total graph-parsing-state) (:finished graph-parsing-state)))
+      [:div.flex.items-center.justify-center.full-height-without-header
+       [:div.flex-1
+        (parsing-progress graph-parsing-state)]]
+
+      :else
+      [:div
+       (cond
+         (and default-home
+              (= :home (state/get-current-route))
+              (not (state/route-has-p?))
+              (:page default-home))
+         (route-handler/redirect-to-page! (:page default-home))
+
+         (and config/publishing?
+              (not default-home)
+              (empty? latest-journals))
+         (route-handler/redirect! {:to :all-pages})
+
+         loading-files?
+         (ui/loading (t :loading-files))
+
+         (seq latest-journals)
+         (journal/journals latest-journals)
+
+         ;; FIXME: why will this happen?
+         :else
+         [:div "bingo"])])))
 
 (rum/defc custom-context-menu < rum/reactive
   []

+ 4 - 0
src/main/frontend/components/sidebar.css

@@ -474,3 +474,7 @@ html[data-theme='dark'] {
 .favorites li.dragging-target {
   border-left: 5px solid green;
 }
+
+.full-height-without-header {
+    height: calc(100vh - var(--ls-headbar-height) - 4rem);
+}

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

@@ -189,6 +189,8 @@
 
 (defn- parse-and-load-file!
   [repo-url file new-graph? metadata]
+  (state/set-parsing-state! (fn [m]
+                              (assoc m :current-parsing-file (:file/path file))))
   (try
     (file-handler/alter-file repo-url
                              (:file/path file)
@@ -201,12 +203,10 @@
       (state/set-parsing-state! (fn [m]
                                   (update m :failed-parsing-files conj [(:file/path file) e])))))
   (state/set-parsing-state! (fn [m]
-                              (-> (update m :finished inc)
-                                  (assoc :current-parsing-file (:file/path file))))))
+                              (update m :finished inc))))
 
 (defn- after-parse
   [repo-url files file-paths first-clone? db-encrypted? re-render? re-render-opts opts graph-added-chan]
-  (state/reset-parsing-state!)
   (load-pages-metadata! repo-url file-paths files true)
   (when first-clone?
     (if (and (not db-encrypted?) (state/enable-encryption? repo-url))
@@ -216,6 +216,7 @@
   (when re-render?
     (ui-handler/re-render-root! re-render-opts))
   (state/pub-event! [:graph/added repo-url opts])
+  (state/reset-parsing-state!)
   (async/offer! graph-added-chan true))
 
 (defn- parse-files-and-create-default-files-inner!
@@ -240,6 +241,7 @@
     (when (seq delete-data) (db/transact! repo-url delete-data))
     (state/set-current-repo! repo-url)
     (state/set-parsing-state! {:total (count support-files')})
+    ;; Synchronous for tests for not breaking anything
     (if util/node-test?
       (do
         (doseq [file support-files']
@@ -249,7 +251,7 @@
         (if-let [file (async/<! chan)]
           (do
             (parse-and-load-file! repo-url file new-graph? metadata)
-            (async/<! (async/timeout 1))
+            (async/<! (async/timeout 10))
             (recur))
           (after-parse repo-url files file-paths first-clone? db-encrypted? re-render? re-render-opts opts graph-added-chan))))
     graph-added-chan))
@@ -293,9 +295,8 @@
 (defn load-repo-to-db!
   [repo-url {:keys [first-clone? diffs nfs-files refresh? new-graph? empty-graph?]}]
   (spec/validate :repos/url repo-url)
-  (when (= :repos (state/get-current-route))
-    (route-handler/redirect-to-home!))
-
+  (route-handler/redirect-to-home!)
+  (state/set-parsing-state! {:graph-loading? true})
   (let [config (or (state/get-config repo-url)
                    (when-let [content (some-> (first (filter #(= (config/get-config-path repo-url) (:file/path %)) nfs-files))
                                               :file/content)]
@@ -672,8 +673,7 @@
           (nfs-rebuild-index! repo ok-handler))
         (rebuild-index! repo))
       (js/setTimeout
-       (fn []
-         (route-handler/redirect-to-home!))
+       (route-handler/redirect-to-home!)
        500))))
 
 (defn git-commit-and-push!