ソースを参照

revert: the web app still needs the refresh button

Because the web app doesn't have the file watcher support, refresh
can be useful when either there're a lot of changes on the disk or
the database is not saved well.
Tienson Qin 4 年 前
コミット
7a2fe9299f
1 ファイル変更90 行追加80 行削除
  1. 90 80
      src/main/frontend/components/repo.cljs

+ 90 - 80
src/main/frontend/components/repo.cljs

@@ -99,87 +99,97 @@
                 state)}
   [repo]
   (when repo
-    (when (string/starts-with? repo "https://")
-      (let [changed-files (state/sub [:repo/changed-files repo])
-            should-push? (seq changed-files)
-            git-status (state/sub [:git/status repo])
-            pushing? (= :pushing git-status)
-            pulling? (= :pulling git-status)
-            git-failed? (contains?
-                         #{:push-failed
-                           :clone-failed
-                           :checkout-failed
-                           :fetch-failed
-                           :merge-failed}
-                         git-status)
-            push-failed? (= :push-failed git-status)
-            last-pulled-at (db/sub-key-value repo :git/last-pulled-at)
-            ;; db-persisted? (state/sub [:db/persisted? repo])
-            editing? (seq (state/sub :editor/editing?))]
-        [:div.flex-row.flex.items-center.cp__repo-indicator
-         (when pushing? svg/loading)
-         (ui/dropdown
-          (fn [{:keys [toggle-fn]}]
-            [:div.cursor.w-2.h-2.sync-status.mr-2
-             {:class (cond
-                       git-failed?
-                       "bg-red-500"
-                       (or
-                        ;; (not db-persisted?)
-                        editing?
-                        should-push? pushing?)
-                       "bg-orange-400"
+    (when-not (or (util/electron?)
+                  (= repo config/local-repo))
+      (let [nfs-repo? (config/local-db? repo)]
+        (if (and nfs-repo? (nfs-handler/supported?))
+          (let [syncing? (state/sub :graph/syncing?)]
+            [:div.opacity-60.refresh.hover:opacity-100
+             [:a.button
+              {:on-click #(nfs-handler/refresh! repo refresh-cb)
+               :title (str "Import files from the local directory: " (config/get-local-dir repo) ".\nVersion: "
+                           version/version)}
+              [:div {:class (if syncing? "animate-spin-reverse" "initial")} svg/refresh]]])
+          (let [changed-files (state/sub [:repo/changed-files repo])
+                should-push? (seq changed-files)
+                git-status (state/sub [:git/status repo])
+                pushing? (= :pushing git-status)
+                pulling? (= :pulling git-status)
+                git-failed? (contains?
+                             #{:push-failed
+                               :clone-failed
+                               :checkout-failed
+                               :fetch-failed
+                               :merge-failed}
+                             git-status)
+                push-failed? (= :push-failed git-status)
+                last-pulled-at (db/sub-key-value repo :git/last-pulled-at)
+                ;; db-persisted? (state/sub [:db/persisted? repo])
+                editing? (seq (state/sub :editor/editing?))]
+            [:div.flex-row.flex.items-center.cp__repo-indicator
+             (when pushing? svg/loading)
+             (ui/dropdown
+              (fn [{:keys [toggle-fn]}]
+                [:div.cursor.w-2.h-2.sync-status.mr-2
+                 {:class (cond
+                           git-failed?
+                           "bg-red-500"
+                           (or
+                            ;; (not db-persisted?)
+                            editing?
+                            should-push? pushing?)
+                           "bg-orange-400"
+                           :else
+                           "bg-green-600")
+                  :style {:border-radius "50%"
+                          :margin-top 2}
+                  :on-mouse-over
+                  (fn [e]
+                    (toggle-fn)
+                    (js/setTimeout common-handler/check-changed-files-status 0))}])
+              (fn [{:keys [toggle-fn]}]
+                (rum/with-context [[t] i18n/*tongue-context*]
+                  [:div.p-2.rounded-md.shadow-xs.bg-base-3.flex.flex-col.sync-content
+                   {:on-mouse-leave toggle-fn}
+                   [:div
+                    [:div
+                     (cond
+                       push-failed?
+                       [:p (t :git/push-failed)]
+                       (and should-push? (seq changed-files))
+                       [:div.changes
+                        [:ul.overflow-y-auto {:style {:max-height 250}}
+                         (for [file changed-files]
+                           [:li {:key (str "sync-" file)}
+                            [:div.flex.flex-row.justify-between.align-items
+                             [:a {:href (rfe/href :file {:path file})}
+                              file]
+                             [:a.ml-4.text-sm.mt-1
+                              {:on-click (fn [e]
+                                           (export-handler/download-file! file))}
+                              [:span (t :download)]]]])]]
                        :else
-                       "bg-green-600")
-              :style {:border-radius "50%"
-                      :margin-top 2}
-              :on-mouse-over
-              (fn [e]
-                (toggle-fn)
-                (js/setTimeout common-handler/check-changed-files-status 0))}])
-          (fn [{:keys [toggle-fn]}]
-            (rum/with-context [[t] i18n/*tongue-context*]
-              [:div.p-2.rounded-md.shadow-xs.bg-base-3.flex.flex-col.sync-content
-               {:on-mouse-leave toggle-fn}
-               [:div
-                [:div
-                 (cond
-                   push-failed?
-                   [:p (t :git/push-failed)]
-                   (and should-push? (seq changed-files))
-                   [:div.changes
-                    [:ul.overflow-y-auto {:style {:max-height 250}}
-                     (for [file changed-files]
-                       [:li {:key (str "sync-" file)}
-                        [:div.flex.flex-row.justify-between.align-items
-                         [:a {:href (rfe/href :file {:path file})}
-                          file]
-                         [:a.ml-4.text-sm.mt-1
-                          {:on-click (fn [e]
-                                       (export-handler/download-file! file))}
-                          [:span (t :download)]]]])]]
-                   :else
-                   [:p (t :git/local-changes-synced)])]
-                ;; [:a.text-sm.font-bold {:href "/diff"} "Check diff"]
-                [:div.flex.flex-row.justify-between.align-items.mt-2
-                 (ui/button (t :git/push)
-                   :on-click (fn [] (state/set-modal! commit/add-commit-message)))
-                 (if pushing? svg/loading)]]
-               [:hr]
-               [:div
-                (when-not (string/blank? last-pulled-at)
-                  [:p {:style {:font-size 12}} (t :git/last-pull)
-                   (str ": " last-pulled-at)])
-                [:div.flex.flex-row.justify-between.align-items
-                 (ui/button (t :git/pull)
-                   :on-click (fn [] (repo-handler/pull-current-repo)))
-                 (if pulling? svg/loading)]
-                [:a.mt-5.text-sm.opacity-50.block
-                 {:on-click (fn []
-                              (export-handler/export-repo-as-zip! repo))}
-                 (t :repo/download-zip)]
-                [:p.pt-2.text-sm.opacity-50
-                 (t :git/version) (str " " version/version)]]])))]))))
+                       [:p (t :git/local-changes-synced)])]
+                    ;; [:a.text-sm.font-bold {:href "/diff"} "Check diff"]
+                    [:div.flex.flex-row.justify-between.align-items.mt-2
+                     (ui/button (t :git/push)
+                       :on-click (fn [] (state/set-modal! commit/add-commit-message)))
+                     (if pushing? svg/loading)]]
+                   [:hr]
+                   [:div
+                    (when-not (string/blank? last-pulled-at)
+                      [:p {:style {:font-size 12}} (t :git/last-pull)
+                       (str ": " last-pulled-at)])
+                    [:div.flex.flex-row.justify-between.align-items
+                     (ui/button (t :git/pull)
+                       :on-click (fn [] (repo-handler/pull-current-repo)))
+                     (if pulling? svg/loading)]
+                    [:a.mt-5.text-sm.opacity-50.block
+                     {:on-click (fn []
+                                  (export-handler/export-repo-as-zip! repo))}
+                     (t :repo/download-zip)]
+                    [:p.pt-2.text-sm.opacity-50
+                     (t :git/version) (str " " version/version)]]])))]))))))
 
 (rum/defc repos-dropdown < rum/reactive
   [on-click]