From 3bb867304dee27a9910e9020245413d72d2c0c77 Mon Sep 17 00:00:00 2001 From: Devon Zuegel Date: Sun, 28 Nov 2021 12:32:29 -0500 Subject: [PATCH] enhance: tidy up repo dropdown in sidebar --- src/main/frontend/components/repo.cljs | 89 ++++++++++++++------------ src/main/frontend/dicts.cljs | 6 +- src/main/frontend/ui.cljs | 13 ++-- 3 files changed, 59 insertions(+), 49 deletions(-) diff --git a/src/main/frontend/components/repo.cljs b/src/main/frontend/components/repo.cljs index a09f2f5da..67d0de9e3 100644 --- a/src/main/frontend/components/repo.cljs +++ b/src/main/frontend/components/repo.cljs @@ -176,6 +176,9 @@ [:p.pt-2.text-sm.opacity-50 (t :git/version) (str " " version/version)]]])))]))) +(defn shorten-repo-name [repo-name] + (last (string/split repo-name #"/"))) + (rum/defc repos-dropdown < rum/reactive [] (when-let [current-repo (state/sub :git/current-repo)] @@ -192,23 +195,26 @@ (db/get-repo-path repo))) repos (state/sub [:me :repos]) repos (remove (fn [r] (= config/local-repo (:url r))) repos) - switch-repos (remove (fn [repo] - (= current-repo (:url repo))) + switch-repos (remove (fn [repo] (= current-repo (:url repo))) repos) repo-links (mapv (fn [{:keys [id url]}] - {:title (get-repo-name url) - :options {:class "ml-1" - :on-click (fn [] - (repo-handler/push-if-auto-enabled! (state/get-current-repo)) - (state/set-current-repo! url) + (let [repo-path (get-repo-name url) + short-repo-name (shorten-repo-name repo-path)] + + {:title [:span short-repo-name] + :hover-detail repo-path ;; show full path on hover + :options {:on-click + (fn [] + (repo-handler/push-if-auto-enabled! (state/get-current-repo)) + (state/set-current-repo! url) ;; load config - (common-handler/reset-config! url nil) - (shortcut/refresh!) - (when-not (= :draw (state/get-current-route)) - (route-handler/redirect-to-home!)) - (when-let [dir-name (config/get-repo-dir url)] - (fs/watch-dir! dir-name)))}}) + (common-handler/reset-config! url nil) + (shortcut/refresh!) + (when-not (= :draw (state/get-current-route)) + (route-handler/redirect-to-home!)) + (when-let [dir-name (config/get-repo-dir url)] + (fs/watch-dir! dir-name)))}})) switch-repos) links (concat repo-links [(when (seq switch-repos) @@ -223,6 +229,7 @@ (or (nfs-handler/supported?) (mobile-util/is-native-platform?))) {:title (t :sync-from-local-files) + :hover-detail (t :sync-from-local-files-detail) :options {:on-click (fn [] (state/pub-event! @@ -234,40 +241,40 @@ :on-click (fn [] (state/close-modal!) (nfs-handler/refresh! (state/get-current-repo) refresh-cb)))]]))}})) - {:title (t :re-index) - :options {:on-click (fn [] - (state/pub-event! - [:modal/show - [:div {:style {:max-width 700}} - [:p "Re-index will discard the current graph, and then processes all the files again as they are currently stored on disk. You will lose unsaved changes and it might take a while. Continue?"] - (ui/button - "Yes" - :on-click (fn [] - (state/close-modal!) - (repo-handler/re-index! - nfs-handler/rebuild-index! - page-handler/create-today-journal!)))]]))}}])] + {:title (t :re-index) + :hover-detail (t :re-index-detail) + :options {:on-click + (fn [] + (state/pub-event! + [:modal/show + [:div {:style {:max-width 700}} + [:p "Re-index will discard the current graph, and then processes all the files again as they are currently stored on disk. You will lose unsaved changes and it might take a while. Continue?"] + (ui/button + "Yes" + :on-click (fn [] + (state/close-modal!) + (repo-handler/re-index! + nfs-handler/rebuild-index! + page-handler/create-today-journal!)))]]))}}])] (when (seq repos) (ui/dropdown-with-links (fn [{:keys [toggle-fn]}] - [:a.item.group.flex.items-center.px-2.py-2.text-sm.font-medium.rounded-md {:on-click toggle-fn} - (ui/icon "database mr-3" {:style {:font-size 20} - :id "database-icon"}) - [:div.graphs - [:span#repo-switch.block.pr-2.whitespace-nowrap - [:span - (let [repo-name (get-repo-name current-repo) - repo-name (if (or (util/electron?) - (mobile-util/is-native-platform?)) - (last - (string/split repo-name #"/")) - repo-name)] - [:span#repo-name.font-medium {:title repo-name} repo-name]) - [:span.dropdown-caret.ml-2 {:style {:border-top-color "#6b7280"}}]]]]]) + (let [repo-path (get-repo-name current-repo) + short-repo-name (if (or (util/electron?) + (mobile-util/is-native-platform?)) + (shorten-repo-name repo-path) + repo-path)] + [:a.item.group.flex.items-center.px-2.py-2.text-sm.font-medium.rounded-md + {:on-click toggle-fn :title repo-path} ;; show full path on hover + (ui/icon "database mr-3" {:style {:font-size 20} :id "database-icon"}) + [:div.graphs + [:span#repo-switch.block.pr-2.whitespace-nowrap + [:span#repo-name.font-medium short-repo-name] + [:span.dropdown-caret.ml-2 {:style {:border-top-color "#6b7280"}}]]]])) links (cond-> {:modal-class (util/hiccup->class "origin-top-right.absolute.left-0.mt-2.rounded-md.shadow-lg")} (seq switch-repos) - (assoc :links-header [:div.font-medium.text-sm.opacity-70.px-4.py-2 + (assoc :links-header [:div.font-medium.text-sm.opacity-60.px-4.pt-2 "Switch to:"])))))))) diff --git a/src/main/frontend/dicts.cljs b/src/main/frontend/dicts.cljs index 046be63dc..8240e19ce 100644 --- a/src/main/frontend/dicts.cljs +++ b/src/main/frontend/dicts.cljs @@ -276,8 +276,10 @@ :cancel "Cancel" :close "Close" :delete "Delete" - :re-index "Re-index (rebuild the graph)" - :sync-from-local-files "Refresh (import changes from local files)" + :re-index "Re-index" + :re-index-detail "Rebuild the graph" + :sync-from-local-files "Refresh" + :sync-from-local-files-detail "Import changes from local files" :unlink "unlink" :search (if config/publishing? "Search" diff --git a/src/main/frontend/ui.cljs b/src/main/frontend/ui.cljs index effe0b783..1b5cfebec 100644 --- a/src/main/frontend/ui.cljs +++ b/src/main/frontend/ui.cljs @@ -130,13 +130,14 @@ (fn [{:keys [close-fn] :as state}] [:div.py-1.rounded-md.shadow-xs (when links-header links-header) - (for [{:keys [options title icon hr]} (if (fn? links) (links) links)] + (for [{:keys [options title icon hr hover-detail]} (if (fn? links) (links) links)] (let [new-options - (assoc options - :on-click (fn [e] - (when-let [on-click-fn (:on-click options)] - (on-click-fn e)) - (close-fn))) + (merge options + {:title hover-detail + :on-click (fn [e] + (when-let [on-click-fn (:on-click options)] + (on-click-fn e)) + (close-fn))}) child (if hr nil [:div