From 112e656f40a5e3993cabcc5dd687e8134a3ac462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Mon, 12 Apr 2021 12:27:10 +0200 Subject: [PATCH] :tada: Sort assets ascending / descending --- .../resources/images/icons/listing-list.svg | 3 ++ .../resources/images/icons/listing-thumbs.svg | 3 ++ .../resources/images/icons/sort-ascending.svg | 3 ++ .../images/icons/sort-descending.svg | 3 ++ .../styles/main/partials/sidebar-assets.scss | 25 ++++++++++++- .../app/main/data/workspace/libraries.cljs | 2 +- frontend/src/app/main/ui/icons.cljs | 4 ++ .../app/main/ui/workspace/sidebar/assets.cljs | 37 +++++++++++++------ 8 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 frontend/resources/images/icons/listing-list.svg create mode 100644 frontend/resources/images/icons/listing-thumbs.svg create mode 100644 frontend/resources/images/icons/sort-ascending.svg create mode 100644 frontend/resources/images/icons/sort-descending.svg diff --git a/frontend/resources/images/icons/listing-list.svg b/frontend/resources/images/icons/listing-list.svg new file mode 100644 index 000000000..d979e5010 --- /dev/null +++ b/frontend/resources/images/icons/listing-list.svg @@ -0,0 +1,3 @@ + + + diff --git a/frontend/resources/images/icons/listing-thumbs.svg b/frontend/resources/images/icons/listing-thumbs.svg new file mode 100644 index 000000000..ac5d98e47 --- /dev/null +++ b/frontend/resources/images/icons/listing-thumbs.svg @@ -0,0 +1,3 @@ + + + diff --git a/frontend/resources/images/icons/sort-ascending.svg b/frontend/resources/images/icons/sort-ascending.svg new file mode 100644 index 000000000..a8907d170 --- /dev/null +++ b/frontend/resources/images/icons/sort-ascending.svg @@ -0,0 +1,3 @@ + + + diff --git a/frontend/resources/images/icons/sort-descending.svg b/frontend/resources/images/icons/sort-descending.svg new file mode 100644 index 000000000..4ba6c45c0 --- /dev/null +++ b/frontend/resources/images/icons/sort-descending.svg @@ -0,0 +1,3 @@ + + + diff --git a/frontend/resources/styles/main/partials/sidebar-assets.scss b/frontend/resources/styles/main/partials/sidebar-assets.scss index ebbe3afff..78059a3a2 100644 --- a/frontend/resources/styles/main/partials/sidebar-assets.scss +++ b/frontend/resources/styles/main/partials/sidebar-assets.scss @@ -118,9 +118,27 @@ cursor: pointer; } + .listing-options { + background-color: $color-gray-60; + display: flex; + justify-content: flex-end; + align-items: center; + padding: $medium $small 0 $small; + + .listing-option-btn { + cursor: pointer; + margin-left: $small; + + svg { + fill: $color-gray-20; + height: 16px; + width: 16px; + } + } + } + .asset-section { background-color: $color-gray-60; - border-top: 1px solid $color-gray-50; padding: $small; font-size: $fs12; color: $color-gray-20; @@ -130,6 +148,11 @@ // max-height: 30rem; // overflow-y: scroll; + // First child is the listing options buttons + &:not(:nth-child(2)) { + border-top: 1px solid $color-gray-50; + } + .asset-title { display: flex; cursor: pointer; diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 59ab84956..fa9d3b279 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -193,7 +193,7 @@ ptk/WatchEvent (watch [_ state s] (let [rchg {:type :add-typography - :typography (assoc typography :ts (.now js/Date))} + :typography typography} uchg {:type :del-typography :id (:id typography)}] (rx/of (dwc/commit-changes [rchg] [uchg] {:commit-local? true}) diff --git a/frontend/src/app/main/ui/icons.cljs b/frontend/src/app/main/ui/icons.cljs index 5c41f28ef..408f2825a 100644 --- a/frontend/src/app/main/ui/icons.cljs +++ b/frontend/src/app/main/ui/icons.cljs @@ -60,6 +60,8 @@ (def libraries (icon-xref :libraries)) (def library (icon-xref :library)) (def line (icon-xref :line)) +(def listing-list (icon-xref :listing-list)) +(def listing-thumbs (icon-xref :listing-thumbs)) (def line-height (icon-xref :line-height)) (def loader (icon-xref :loader)) (def lock (icon-xref :lock)) @@ -117,6 +119,8 @@ (def shape-vdistribute (icon-xref :shape-vdistribute)) (def size-horiz (icon-xref :size-horiz)) (def size-vert (icon-xref :size-vert)) +(def sort-ascending (icon-xref :sort-ascending)) +(def sort-descending (icon-xref :sort-descending)) (def strikethrough (icon-xref :strikethrough)) (def stroke (icon-xref :stroke)) (def sublevel (icon-xref :sublevel)) diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs index 38f86df09..cad955034 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs @@ -794,7 +794,7 @@ [(t locale "workspace.assets.delete") handle-delete-typography]]}] (when open? [:div.asset-list - (for [typography (sort-by :ts typographies)] + (for [typography typographies] [:& typography-entry {:key (:id typography) :typography typography @@ -852,12 +852,13 @@ (l/derived refs/workspace-local))) (defn apply-filters - [coll filters] - (->> coll - (filter (fn [item] - (or (matches-search (:name item "!$!") (:term filters)) - (matches-search (:value item "!$!") (:term filters))))) - (sort-by #(str/lower (:name %))))) + [coll filters reverse-sort?] + (let [comp-fn (if reverse-sort? > <)] + (->> coll + (filter (fn [item] + (or (matches-search (:name item "!$!") (:term filters)) + (matches-search (:value item "!$!") (:term filters))))) + (sort-by #(str/lower (:name %)) comp-fn)))) (mf/defc file-library [{:keys [file local? default-open? filters locale] :as props}] @@ -871,6 +872,9 @@ (d/nilv true))) shared? (:is-shared file) router (mf/deref refs/router) + + reverse-sort? (mf/use-state false) + toggle-open (st/emitf (dwl/set-assets-box-open (:id file) :library (not open?))) url (rt/resolve router :workspace @@ -879,16 +883,21 @@ {:page-id (get-in file [:data :pages 0])}) colors-ref (mf/use-memo (mf/deps (:id file)) #(file-colors-ref (:id file))) - colors (apply-filters (mf/deref colors-ref) filters) + colors (apply-filters (mf/deref colors-ref) filters @reverse-sort?) typography-ref (mf/use-memo (mf/deps (:id file)) #(file-typography-ref (:id file))) - typographies (apply-filters (mf/deref typography-ref) filters) + typographies (apply-filters (mf/deref typography-ref) filters @reverse-sort?) media-ref (mf/use-memo (mf/deps (:id file)) #(file-media-ref (:id file))) - media (apply-filters (mf/deref media-ref) filters) + media (apply-filters (mf/deref media-ref) filters @reverse-sort?) components-ref (mf/use-memo (mf/deps (:id file)) #(file-components-ref (:id file))) - components (apply-filters (mf/deref components-ref) filters)] + components (apply-filters (mf/deref components-ref) filters @reverse-sort?) + + toggle-sort + (mf/use-callback + (fn [event] + (swap! reverse-sort? not)))] [:div.tool-window [:div.tool-window-bar.library-bar @@ -928,6 +937,12 @@ (or (> (count typographies) 0) (str/empty? (:term filters))))] [:div.tool-window-content + [:div.listing-options + [:div.listing-option-btn {:on-click toggle-sort} + (if @reverse-sort? + i/sort-descending + i/sort-ascending)] + [:div.listing-option-btn i/listing-thumbs]] (when show-components? [:& components-box {:file-id (:id file) :local? local?