enhance: graphs switcher UX

pull/2142/head^2
Tienson Qin 2021-06-09 09:20:42 +08:00
parent 05d51925a5
commit 7e68248670
4 changed files with 53 additions and 54 deletions

View File

@ -88,13 +88,6 @@
:options {:href (rfe/href :graph)} :options {:href (rfe/href :graph)}
:icon svg/graph-sm}) :icon svg/graph-sm})
(when (or logged?
(util/electron?)
(and (nfs/supported?) current-repo))
{:title (t :all-graphs)
:options {:href (rfe/href :repos)}
:icon svg/repos-sm})
(when current-repo (when current-repo
{:title (t :all-pages) {:title (t :all-pages)
:options {:href (rfe/href :all-pages)} :options {:href (rfe/href :all-pages)}

View File

@ -50,13 +50,13 @@
(when (nfs-handler/supported?) (when (nfs-handler/supported?)
[:div.mr-8 [:div.mr-8
(ui/button (ui/button
(t :open-a-directory) (t :open-a-directory)
:on-click page-handler/ls-dir-files!)]) :on-click page-handler/ls-dir-files!)])
(when (and (state/logged?) (not (util/electron?))) (when (and (state/logged?) (not (util/electron?)))
(ui/button (ui/button
"Add another git repo" "Add another git repo"
:href (rfe/href :repo-add nil {:graph-types "github"}) :href (rfe/href :repo-add nil {:graph-types "github"})
:intent "logseq"))] :intent "logseq"))]
(for [{:keys [id url] :as repo} repos] (for [{:keys [id url] :as repo} repos]
(let [local? (config/local-db? url)] (let [local? (config/local-db? url)]
[:div.flex.justify-between.mb-1 {:key id} [:div.flex.justify-between.mb-1 {:key id}
@ -94,7 +94,7 @@
(when-not (= repo config/local-repo) (when-not (= repo config/local-repo)
(if (and nfs-repo? (nfs-handler/supported?)) (if (and nfs-repo? (nfs-handler/supported?))
(let [syncing? (state/sub :graph/syncing?)] (let [syncing? (state/sub :graph/syncing?)]
[:div.ml-2.mr-2.opacity-30.refresh.hover:opacity-100 {:class (if syncing? "loader" "initial")} [:div.ml-3.mr-1.mt-1.opacity-30.refresh.hover:opacity-100 {:class (if syncing? "loader" "initial")}
[:a [:a
{:on-click #(nfs-handler/refresh! repo {:on-click #(nfs-handler/refresh! repo
repo-handler/create-today-journal!) repo-handler/create-today-journal!)
@ -161,10 +161,10 @@
[:span (t :download)]]]])]] [:span (t :download)]]]])]]
:else :else
[:p (t :git/local-changes-synced)])] [:p (t :git/local-changes-synced)])]
;; [:a.text-sm.font-bold {:href "/diff"} "Check diff"] ;; [:a.text-sm.font-bold {:href "/diff"} "Check diff"]
[:div.flex.flex-row.justify-between.align-items.mt-2 [:div.flex.flex-row.justify-between.align-items.mt-2
(ui/button (t :git/push) (ui/button (t :git/push)
:on-click (fn [] (state/set-modal! commit/add-commit-message))) :on-click (fn [] (state/set-modal! commit/add-commit-message)))
(if pushing? svg/loading)]] (if pushing? svg/loading)]]
[:hr] [:hr]
[:div [:div
@ -173,7 +173,7 @@
(str ": " last-pulled-at)]) (str ": " last-pulled-at)])
[:div.flex.flex-row.justify-between.align-items [:div.flex.flex-row.justify-between.align-items
(ui/button (t :git/pull) (ui/button (t :git/pull)
:on-click (fn [] (repo-handler/pull-current-repo))) :on-click (fn [] (repo-handler/pull-current-repo)))
(if pulling? svg/loading)] (if pulling? svg/loading)]
[:a.mt-5.text-sm.opacity-50.block [:a.mt-5.text-sm.opacity-50.block
{:on-click (fn [] {:on-click (fn []
@ -185,29 +185,34 @@
(rum/defc repos-dropdown < rum/reactive (rum/defc repos-dropdown < rum/reactive
[on-click] [on-click]
(when-let [current-repo (state/sub :git/current-repo)] (when-let [current-repo (state/sub :git/current-repo)]
(let [logged? (state/logged?) (rum/with-context [[t] i18n/*tongue-context*]
local-repo? (= current-repo config/local-repo) (let [get-repo-name (fn [repo]
get-repo-name (fn [repo] (if (config/local-db? repo)
(if (config/local-db? repo) (config/get-local-dir repo)
(config/get-local-dir repo) (db/get-repo-path repo)))
(db/get-repo-path repo)))] repos (state/sub [:me :repos])
(let [repos (->> (state/sub [:me :repos]) repos (remove (fn [r] (= config/local-repo (:url r))) repos)
(remove (fn [r] (= config/local-repo (:url r)))))] switch-repos (remove (fn [repo]
(cond (= current-repo (:url repo)))
(> (count repos) 1) repos)]
(when (seq repos)
(ui/dropdown-with-links (ui/dropdown-with-links
(fn [{:keys [toggle-fn]}] (fn [{:keys [toggle-fn]}]
[:a#repo-switch.fade-link {:on-click toggle-fn} [:a#repo-switch.fade-link {:on-click toggle-fn}
(let [repo-name (get-repo-name current-repo)
repo-name (if (util/electron?) [:span
(last (string/split repo-name #"/")) [:span.repo-plus svg/plus]
repo-name)] (let [repo-name (get-repo-name current-repo)
[:span#repo-name repo-name]) repo-name (if (util/electron?)
[:span.dropdown-caret.ml-1 {:style {:border-top-color "#6b7280"}}]]) (last (string/split repo-name #"/"))
repo-name)]
[:span#repo-name repo-name])
[:span.dropdown-caret.ml-1 {:style {:border-top-color "#6b7280"}}]]])
(mapv (mapv
(fn [{:keys [id url]}] (fn [{:keys [id url]}]
{:title (get-repo-name url) {:title (get-repo-name url)
:options {:on-click (fn [] :options {:class "ml-1"
:on-click (fn []
(repo-handler/push-if-auto-enabled! (state/get-current-repo)) (repo-handler/push-if-auto-enabled! (state/get-current-repo))
(state/set-current-repo! url) (state/set-current-repo! url)
;; load config ;; load config
@ -216,23 +221,18 @@
(route-handler/redirect-to-home!)) (route-handler/redirect-to-home!))
(when on-click (when on-click
(on-click url)))}}) (on-click url)))}})
(remove (fn [repo] switch-repos)
(= current-repo (:url repo))) (cond->
repos)) {:modal-class (util/hiccup->class
{:modal-class (util/hiccup->class "origin-top-right.absolute.left-0.mt-2.w-48.rounded-md.shadow-lg")
"origin-top-right.absolute.left-0.mt-2.w-48.rounded-md.shadow-lg ")}) :links-footer [:div
(when (seq switch-repos) [:hr.my-4])
(and current-repo (not local-repo?)) [:a {:class "block px-4 py-2 text-sm text-gray-700 transition ease-in-out duration-150 cursor menu-link"
(let [repo-name (get-repo-name current-repo)] :href (rfe/href :repo-add)}
(if (config/local-db? current-repo) (t :new-graph)]
[:span.fade-link#repo-name [:a {:class "block px-4 py-2 text-sm text-gray-700 transition ease-in-out duration-150 cursor menu-link"
(if (util/electron?) :href (rfe/href :repos)}
(last (string/split repo-name #"/")) (t :all-graphs)]]}
repo-name)] (seq switch-repos)
[:a.fade-link#repo-name (assoc :links-header [:div.font-medium.text-sm.opacity-70.px-4.py-2
{:href current-repo "Switch to:"]))))))))
:target "_blank"}
repo-name]))
:else
nil)))))

View File

@ -7,4 +7,9 @@
margin: 0.25rem 0; margin: 0.25rem 0;
} }
} }
} }
.repo-plus svg {
display: inline;
transform: scale(0.7);
}

View File

@ -240,6 +240,7 @@
:page-search "Search in the current page" :page-search "Search in the current page"
:new-page "New page" :new-page "New page"
:new-file "New file" :new-file "New file"
:new-graph "Add new graph"
:graph "Graph" :graph "Graph"
:graph-view "View Graph" :graph-view "View Graph"
:publishing "Publishing" :publishing "Publishing"