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

@ -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!)
@ -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)))
(let [repos (->> (state/sub [:me :repos]) repos (state/sub [:me :repos])
(remove (fn [r] (= config/local-repo (:url r)))))] repos (remove (fn [r] (= config/local-repo (:url r))) repos)
(cond switch-repos (remove (fn [repo]
(> (count repos) 1) (= current-repo (:url repo)))
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}
[:span
[:span.repo-plus svg/plus]
(let [repo-name (get-repo-name current-repo) (let [repo-name (get-repo-name current-repo)
repo-name (if (util/electron?) repo-name (if (util/electron?)
(last (string/split repo-name #"/")) (last (string/split repo-name #"/"))
repo-name)] repo-name)]
[:span#repo-name repo-name]) [:span#repo-name repo-name])
[:span.dropdown-caret.ml-1 {:style {:border-top-color "#6b7280"}}]]) [: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
(and current-repo (not local-repo?)) (when (seq switch-repos) [:hr.my-4])
(let [repo-name (get-repo-name current-repo)] [:a {:class "block px-4 py-2 text-sm text-gray-700 transition ease-in-out duration-150 cursor menu-link"
(if (config/local-db? current-repo) :href (rfe/href :repo-add)}
[:span.fade-link#repo-name (t :new-graph)]
(if (util/electron?) [:a {:class "block px-4 py-2 text-sm text-gray-700 transition ease-in-out duration-150 cursor menu-link"
(last (string/split repo-name #"/")) :href (rfe/href :repos)}
repo-name)] (t :all-graphs)]]}
[:a.fade-link#repo-name (seq switch-repos)
{:href current-repo (assoc :links-header [:div.font-medium.text-sm.opacity-70.px-4.py-2
:target "_blank"} "Switch to:"]))))))))
repo-name]))
:else
nil)))))

View File

@ -8,3 +8,8 @@
} }
} }
} }
.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"