enhance: add sync from local files (the old refresh way)

pull/2777/head
Tienson Qin 2021-09-06 17:57:33 +08:00
parent a16e5c98ba
commit 571c81af30
2 changed files with 91 additions and 93 deletions

View File

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

View File

@ -250,7 +250,8 @@
:cancel "Cancel" :cancel "Cancel"
:close "Close" :close "Close"
:delete "Delete" :delete "Delete"
:re-index "Re-index" :re-index "Re-index (rebuild the graph)"
:sync-from-local-files "Sync from local files"
:unlink "unlink" :unlink "unlink"
:search (if config/publishing? :search (if config/publishing?
"Search" "Search"