From 50932dea549200ad23d32571baa00272caf7fb3b Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 31 Aug 2023 09:58:04 +0200 Subject: [PATCH] :bug: Fix list view is discarded on tab change for assets sidebar --- CHANGES.md | 6 ++++ .../src/app/main/data/workspace/assets.cljs | 28 +++++++++++++++++++ .../app/main/ui/workspace/sidebar/assets.cljs | 22 ++++++++++++--- version.txt | 2 +- 4 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 frontend/src/app/main/data/workspace/assets.cljs diff --git a/CHANGES.md b/CHANGES.md index 8529b03ec..f2f50ec2f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # CHANGELOG +## 1.19.3 + +### :bug: Bugs fixed + +- List view is discarded on tab change on Workspace Assets Sidebar tab [Github #3547](https://github.com/penpot/penpot/issues/3547) + ## 1.19.2 ### :sparkles: New features diff --git a/frontend/src/app/main/data/workspace/assets.cljs b/frontend/src/app/main/data/workspace/assets.cljs new file mode 100644 index 000000000..7db9cc1ce --- /dev/null +++ b/frontend/src/app/main/data/workspace/assets.cljs @@ -0,0 +1,28 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS INC + +(ns app.main.data.workspace.assets + "Workspace assets management events and helpers." + (:require + [app.util.storage :refer [storage]])) + +(defn get-current-assets-ordering + [] + (let [ordering (::ordering @storage)] + (or ordering :asc))) + +(defn set-current-assets-ordering! + [ordering] + (swap! storage assoc ::ordering ordering)) + +(defn get-current-assets-list-style + [] + (let [list-style (::list-style @storage)] + (or list-style :thumbs))) + +(defn set-current-assets-list-style! + [list-style] + (swap! storage assoc ::list-style list-style)) diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs index b352b755e..5a5f381e6 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs @@ -16,6 +16,7 @@ [app.main.data.events :as ev] [app.main.data.modal :as modal] [app.main.data.workspace :as dw] + [app.main.data.workspace.assets :as dwa] [app.main.data.workspace.colors :as dc] [app.main.data.workspace.libraries :as dwl] [app.main.data.workspace.media :as dwm] @@ -2424,19 +2425,32 @@ [] (let [components-v2 (mf/use-ctx ctx/components-v2) read-only? (mf/use-ctx ctx/workspace-read-only?) + filters* (mf/use-state {:term "" :section :all - :ordering :asc - :list-style :thumbs}) + :ordering (dwa/get-current-assets-ordering) + :list-style (dwa/get-current-assets-list-style)}) filters (deref filters*) term (:term filters) + ordering (:ordering filters) + list-style (:list-style filters) toggle-ordering - (mf/use-fn #(swap! filters* update :ordering toggle-values [:asc :desc])) + (mf/use-fn + (mf/deps ordering) + (fn [] + (let [new-value (toggle-values ordering [:asc :desc])] + (swap! filters* assoc :ordering new-value) + (dwa/set-current-assets-ordering! new-value)))) toggle-list-style - (mf/use-fn #(swap! filters* update :list-style toggle-values [:thumbs :list])) + (mf/use-fn + (mf/deps list-style) + (fn [] + (let [new-value (toggle-values list-style [:thumbs :list])] + (swap! filters* assoc :list-style new-value) + (dwa/set-current-assets-list-style! new-value)))) on-search-term-change (mf/use-fn diff --git a/version.txt b/version.txt index 836ae4eda..1b92e588b 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.19.2 +1.19.3