1
0
Эх сурвалжийг харах

enhance: display downloading status in repo switch

Tienson Qin 1 жил өмнө
parent
commit
d50e1dee97

+ 32 - 31
src/main/frontend/components/property/value.cljs

@@ -83,10 +83,11 @@
                 (js/Date. (date/journal-title->long title))
                 value)
         value' (when-not (string/blank? value)
-                 (try
-                   (tc/to-local-date value)
-                   (catch :default e
-                     (js/console.error e))))
+                 (when-not (uuid? value)
+                   (try
+                     (tc/to-local-date value)
+                     (catch :default e
+                       (js/console.error e)))))
         initial-day (some-> value' (.getTime) (js/Date.))
         initial-month (when value'
                         (js/Date. (.getYear value') (.getMonth value')))]
@@ -100,35 +101,35 @@
                        (let [gd (goog.date.Date. (.getFullYear d) (.getMonth d) (.getDate d))]
                          (let [journal (date/js-date->journal-title gd)]
                            (p/do!
-                             (when-not (db/entity [:block/name (util/page-name-sanity-lc journal)])
-                               (page-handler/<create! journal {:redirect? false
-                                                               :create-first-block? false}))
-                             (when (fn? on-change)
-                               (on-change (db/entity [:block/name (util/page-name-sanity-lc journal)])))
-                             (shui/popup-hide! id)
-                             (exit-edit-property))))))]
+                            (when-not (db/entity [:block/name (util/page-name-sanity-lc journal)])
+                              (page-handler/<create! journal {:redirect? false
+                                                              :create-first-block? false}))
+                            (when (fn? on-change)
+                              (on-change (db/entity [:block/name (util/page-name-sanity-lc journal)])))
+                            (shui/popup-hide! id)
+                            (exit-edit-property))))))]
                (shui/calendar
-                 {:mode "single"
-                  :initial-focus true
-                  :selected initial-day
-                  :default-month initial-month
-                  :class-names {:months ""}
-                  :on-day-key-down (fn [^js d _ ^js e]
-                                     (when (= "Enter" (.-key e))
-                                       (select-handler! d)))
-                  :on-select select-handler!})))]
+                {:mode "single"
+                 :initial-focus true
+                 :selected initial-day
+                 :default-month initial-month
+                 :class-names {:months ""}
+                 :on-day-key-down (fn [^js d _ ^js e]
+                                    (when (= "Enter" (.-key e))
+                                      (select-handler! d)))
+                 :on-select select-handler!})))]
        (shui/button
-         {:class "jtrigger !p-1"
-          :variant :text
-          :size :sm
-          :on-click (fn [e]
-                      (if config/publishing?
-                        (navigate-to-date-page value)
-                        (do
-                          (util/stop e)
-                          (shui/popup-show! (.-target e) content-fn
-                            {:align "start" :auto-focus? true}))))}
-         (ui/icon "calendar" {:size 16})))
+        {:class "jtrigger !p-1"
+         :variant :text
+         :size :sm
+         :on-click (fn [e]
+                     (if config/publishing?
+                       (navigate-to-date-page value)
+                       (do
+                         (util/stop e)
+                         (shui/popup-show! (.-target e) content-fn
+                                           {:align "start" :auto-focus? true}))))}
+        (ui/icon "calendar" {:size 16})))
 
      (when page
        (when-let [page-cp (state/get-component :block/page-cp)]

+ 21 - 16
src/main/frontend/components/repo.cljs

@@ -164,7 +164,7 @@
     (p/let [multiple-windows? (ipc/ipc "graphHasMultipleWindows" (state/get-current-repo))]
       (reset! (::electron-multiple-windows? state) multiple-windows?))))
 
-(defn- repos-dropdown-links [repos current-repo *multiple-windows? & {:as opts}]
+(defn- repos-dropdown-links [repos current-repo downloading-graph-id *multiple-windows? & {:as opts}]
   (let [switch-repos (if-not (nil? current-repo)
                        (remove (fn [repo] (= current-repo (:url repo))) repos) repos) ; exclude current repo
         repo-links (mapv
@@ -177,28 +177,32 @@
                                        :else GraphName)
                             short-repo-name (if (or local? db-only?)
                                               (text-util/get-graph-name-from-path repo-url)
-                                              GraphName)]
+                                              GraphName)
+                            downloading? (and downloading-graph-id (= GraphUUID downloading-graph-id))]
                         (when short-repo-name
                           {:title        [:span.flex.items-center.whitespace-nowrap short-repo-name
                                           (when remote? [:span.pl-1.flex.items-center
                                                          {:title (str "<" GraphName "> #" GraphUUID)}
-                                                         (ui/icon "cloud" {:size 18})])]
+                                                         (ui/icon "cloud" {:size 18})
+                                                         (when downloading?
+                                                           [:span.opacity.text-sm.pl-1 "downloading"])])]
                            :hover-detail repo-url ;; show full path on hover
                            :options      {:on-click (fn [e]
-                                                      (when-let [on-click (:on-click opts)]
-                                                        (on-click e))
-                                                      (if (and (gobj/get e "shiftKey")
-                                                               (not (and rtc-graph? remote?)))
-                                                        (state/pub-event! [:graph/open-new-window url])
-                                                        (cond
-                                                          (and rtc-graph? remote?)
-                                                          (state/pub-event! [:rtc/download-remote-graph GraphName GraphUUID])
+                                                      (when-not downloading?
+                                                        (when-let [on-click (:on-click opts)]
+                                                          (on-click e))
+                                                        (if (and (gobj/get e "shiftKey")
+                                                                 (not (and rtc-graph? remote?)))
+                                                          (state/pub-event! [:graph/open-new-window url])
+                                                          (cond
+                                                            (and rtc-graph? remote?)
+                                                            (state/pub-event! [:rtc/download-remote-graph GraphName GraphUUID])
 
-                                                          (or local? db-only?)
-                                                          (state/pub-event! [:graph/switch url])
+                                                            (or local? db-only?)
+                                                            (state/pub-event! [:graph/switch url])
 
-                                                          :else
-                                                          (state/pub-event! [:graph/pull-down-remote-graph graph]))))}})))
+                                                            :else
+                                                            (state/pub-event! [:graph/pull-down-remote-graph graph])))))}})))
                     switch-repos)
         refresh-link (let [nfs-repo? (config/local-file-based-graph? current-repo)]
                        (when (and nfs-repo?
@@ -240,9 +244,10 @@
       (let [repos (state/sub [:me :repos])
             remotes (state/sub [:file-sync/remote-graphs :graphs])
             rtc-graphs (state/sub :rtc/graphs)
+            downloading-graph-id (state/sub :rtc/downloading-graph-uuid)
             repos (if (and (or (seq remotes) (seq rtc-graphs)) login?)
                     (repo-handler/combine-local-&-remote-graphs repos (concat remotes rtc-graphs)) repos)
-            links (repos-dropdown-links repos current-repo multiple-windows? opts)
+            links (repos-dropdown-links repos current-repo downloading-graph-id multiple-windows? opts)
             render-content (fn [{:keys [toggle-fn]}]
                              (let [remote? (:remote? (first (filter #(= current-repo (:url %)) repos)))
                                    repo-name (db/get-repo-name current-repo)

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

@@ -7,13 +7,11 @@
             [frontend.util :as util]))
 
 (rum/defc details
-  [{:keys [unpushed-block-update-count]} uploading? downloading?]
+  [{:keys [unpushed-block-update-count]} uploading?]
   [: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)
@@ -24,20 +22,18 @@
   (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 (or graph-uuid downloading?)
+    (when graph-uuid
       [:div.cp__rtc-sync
        [:div.cp__rtc-sync-indicator
         [:a.button.cloud
          {:on-click #(shui/popup-show! (.-target %)
-                                       (details state uploading? downloading?)
+                                       (details state uploading?)
                                        {:align "end"})
           :class    (util/classnames [{:on (and online? (= :open rtc-state))
                                        :idle (and online? (= :open rtc-state) (zero? unpushed-block-update-count)
-                                                  (not uploading?)
-                                                  (not downloading?))
-                                       :queuing (or uploading? downloading? (pos? unpushed-block-update-count))}])}
+                                                  (not uploading?))
+                                       :queuing (or uploading? (pos? unpushed-block-update-count))}])}
          [:span.flex.items-center
           (ui/icon "cloud" {:size ui/icon-size})]]]])))

+ 2 - 2
src/main/frontend/handler/db_based/rtc.cljs

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

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

@@ -288,7 +288,7 @@
 
       :rtc/state                             (atom {})
       :rtc/uploading?                        false
-      :rtc/downloading?                      false
+      :rtc/downloading-graph-uuid            nil
       :rtc/graphs                            []
       :rtc/online-info                       (atom {})
       ;; graph-url -> {:in-transaction? Boolean :txs []}