From d8027936b44c3165a6adb91932d8d1ea582e89cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 25 Aug 2023 13:50:21 +0200 Subject: [PATCH] :sparkles: Small enhancements --- frontend/src/app/main/ui/messages.cljs | 10 +- .../src/app/main/ui/workspace/libraries.cljs | 91 ++++++++++--------- 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/frontend/src/app/main/ui/messages.cljs b/frontend/src/app/main/ui/messages.cljs index 2f0ec0e51..e5719d3d3 100644 --- a/frontend/src/app/main/ui/messages.cljs +++ b/frontend/src/app/main/ui/messages.cljs @@ -6,8 +6,10 @@ (ns app.main.ui.messages (:require + [app.common.data :as d] + [app.common.data.macros :as dm] [app.common.uuid :as uuid] - [app.main.data.messages :as dm] + [app.main.data.messages :as dmsg] [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.icons :as i] @@ -39,8 +41,8 @@ :role role} [:span content - (for [link links] - [:* {:key (uuid/next)} + (for [[index link] (d/enumerate links)] + [:* {:key (dm/str "link-" index)} " " [:a.link {:on-click (:callback link)} (:label link)]])] (when (or (= controls :bottom-actions) (= controls :inline-actions)) @@ -55,7 +57,7 @@ (mf/defc notifications [] (let [message (mf/deref refs/message) - on-close #(st/emit! dm/hide)] + on-close #(st/emit! dmsg/hide)] (when message [:& banner (assoc message :position (or (:position message) :fixed) diff --git a/frontend/src/app/main/ui/workspace/libraries.cljs b/frontend/src/app/main/ui/workspace/libraries.cljs index 14862dc1f..eb330289a 100644 --- a/frontend/src/app/main/ui/workspace/libraries.cljs +++ b/frontend/src/app/main/ui/workspace/libraries.cljs @@ -394,6 +394,48 @@ (tr "workspace.libraries.no-shared-libraries-available") (tr "workspace.libraries.no-matches-for" search-term))])])]]))) +(defn- extract-assets + [file-data library summary?] + (let [exceeded (volatile! {:components false + :colors false + :typographies false}) + + truncate (fn [asset-type items] + (if (and summary? (> (count items) 5)) + (do + (vswap! exceeded assoc asset-type true) + (take 5 items)) + items)) + + assets (dwl/assets-need-sync library file-data) + + component-ids (into #{} (->> assets + (filter #(= (:asset-type %) :component)) + (map :asset-id))) + color-ids (into #{} (->> assets + (filter #(= (:asset-type %) :color)) + (map :asset-id))) + typography-ids (into #{} (->> assets + (filter #(= (:asset-type %) :typography)) + (map :asset-id))) + + components (->> component-ids + (map #(ctkl/get-component (:data library) %)) + (sort-by #(str/lower (:name %))) + (truncate :components)) + colors (->> color-ids + (map #(ctcl/get-color (:data library) %)) + (sort-by #(str/lower (:name %))) + (truncate :colors)) + typographies (->> typography-ids + (map #(ctyl/get-typography (:data library) %)) + (sort-by #(str/lower (:name %))) + (truncate :typographies))] + + [library @exceeded {:components components + :colors colors + :typographies typographies}])) + (mf/defc updates-tab {::mf/wrap-props false} [{:keys [file-id file-data libraries]}] @@ -403,54 +445,13 @@ updating? (deref updating?*) see-all-assets - (fn [] - (reset! summary?* false)) - - extract-assets - (fn [library] - (let [exceeded (volatile! {:components false - :colors false - :typographies false}) - - truncate (fn [asset-type items] - (if (and summary? (> (count items) 5)) - (do - (vswap! exceeded assoc asset-type true) - (take 5 items)) - items)) - - assets (dwl/assets-need-sync library file-data) - - component-ids (into #{} (->> assets - (filter #(= (:asset-type %) :component)) - (map :asset-id))) - color-ids (into #{} (->> assets - (filter #(= (:asset-type %) :color)) - (map :asset-id))) - typography-ids (into #{} (->> assets - (filter #(= (:asset-type %) :typography)) - (map :asset-id))) - - components (->> component-ids - (map #(ctkl/get-component (:data library) %)) - (sort-by #(str/lower (:name %))) - (truncate :components)) - colors (->> color-ids - (map #(ctcl/get-color (:data library) %)) - (sort-by #(str/lower (:name %))) - (truncate :colors)) - typographies (->> typography-ids - (map #(ctyl/get-typography (:data library) %)) - (sort-by #(str/lower (:name %))) - (truncate :typographies))] - - [library @exceeded {:components components - :colors colors - :typographies typographies}])) + (mf/use-fn + (fn [] + (reset! summary?* false))) libs-assets (mf/with-memo [file-data libraries summary?*] (->> (vals libraries) - (map extract-assets) + (map #(extract-assets file-data % summary?)) (filter (fn [[_ _ {:keys [components colors typographies]}]] (or (seq components) (seq colors)