Browse Source

enhance: downloading status hint

Tienson Qin 1 year ago
parent
commit
16d344ad8c

+ 9 - 5
src/main/frontend/components/rtc/indicator.cljs

@@ -7,11 +7,13 @@
             [frontend.util :as util]))
 
 (rum/defc details
-  [{:keys [unpushed-block-update-count]} uploading?]
+  [{:keys [unpushed-block-update-count]} uploading? downloading?]
   [:div.cp__rtc-sync-details.text-sm.p-1
    (cond
      uploading?
      "Uploading..."
+     downloading?
+     "Downloading..."
      (zero? unpushed-block-update-count)
      "All local changes have been synced"
      (pos? unpushed-block-update-count)
@@ -22,18 +24,20 @@
   (let [_                       (state/sub :auth/id-token)
         online?                 (state/sub :network/online?)
         uploading?              (state/sub :rtc/uploading?)
+        downloading?            (state/sub :rtc/downloading?)
         {:keys [graph-uuid rtc-state unpushed-block-update-count] :as state}
         (state/sub :rtc/state)]
-    (when graph-uuid
+    (when (or graph-uuid downloading?)
       [:div.cp__rtc-sync
        [:div.cp__rtc-sync-indicator
         [:a.button.cloud
          {:on-click #(shui/popup-show! (.-target %)
-                                       (details state uploading?)
+                                       (details state uploading? downloading?)
                                        {:align "end"})
           :class    (util/classnames [{:on (and online? (= :open rtc-state))
                                        :idle (and online? (= :open rtc-state) (zero? unpushed-block-update-count)
-                                                  (not uploading?))
-                                       :queuing (or uploading? (pos? unpushed-block-update-count))}])}
+                                                  (not uploading?)
+                                                  (not downloading?))
+                                       :queuing (or uploading? downloading? (pos? unpushed-block-update-count))}])}
          [:span.flex.items-center
           (ui/icon "cloud" {:size ui/icon-size})]]]])))

+ 6 - 1
src/main/frontend/handler/db_based/rtc.cljs

@@ -27,9 +27,14 @@
 (defn <rtc-download-graph!
   [repo graph-uuid]
   (when-let [^js worker @state/*db-worker]
+    (state/set-state! :rtc/downloading? true)
     (user-handler/<wrap-ensure-id&access-token
      (let [token (state/get-auth-id-token)]
-       (.rtc-download-graph worker repo token graph-uuid)))))
+       (->
+        (.rtc-download-graph worker repo token graph-uuid)
+        (p/finally
+          (fn []
+            (state/set-state! :rtc/downloading? false))))))))
 
 (defn <rtc-start!
   [repo]

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

@@ -287,6 +287,8 @@
       ;; graph-uuid -> ...
 
       :rtc/state                             (atom {})
+      :rtc/uploading?                        false
+      :rtc/downloading?                      false
       :rtc/graphs                            []
       ;; graph-url -> {:in-transaction? Boolean :txs []}
       :rtc/remote-batch-tx-state             {}