From 68595e90ebd51a5148a360d3e67a7a718443688e Mon Sep 17 00:00:00 2001 From: Dream <42954461+eureka0928@users.noreply.github.com> Date: Tue, 14 Apr 2026 06:31:25 -0400 Subject: [PATCH] :sparkles: Persist asset search query when switching sidebar tabs (#8985) When users switch between the Layers and Assets sidebar tabs, the `assets-toolbox*` component unmounts and its local `use-state` is discarded, so the search query and section filter are lost. Lift the search term and section filter into a per-file, in-memory session atom that survives tab switches but doesn't leak across files or persist across reloads. Ordering and list-style continue to use localStorage as before. Closes #2913 Signed-off-by: eureka0928 Co-authored-by: Andrey Antukh --- CHANGES.md | 1 + .../app/main/ui/workspace/sidebar/assets.cljs | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 709b24a7cf..aece6a2a85 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -64,6 +64,7 @@ - Access Tokens look & feel refinement [Taiga #13114](https://tree.taiga.io/project/penpot/us/13114) - Enhance readability of applied tokens in plugins API [Taiga #13714](https://tree.taiga.io/project/penpot/issue/13714) +- Persist asset search query and section filter when switching sidebar tabs (by @eureka0928) [Github #2913](https://github.com/penpot/penpot/issues/2913) ### :bug: Bugs fixed diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs index dc7fd0a50d..206a16f8e0 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs @@ -70,16 +70,24 @@ [v a b] (if (= v a) b a)) +;; Per-file, session-scoped (in-memory only) so the search term and section +;; filter survive switching between the Layers and Assets sidebar tabs without +;; leaking across files or persisting across reloads. +(defonce ^:private session-filters* + (atom {})) + (mf/defc assets-toolbox* {::mf/wrap [mf/memo]} [{:keys [size file-id]}] (let [read-only? (mf/use-ctx ctx/workspace-read-only?) filters* (mf/use-state - {:term "" - :section "all" - :ordering (dwa/get-current-assets-ordering) - :list-style (dwa/get-current-assets-list-style) - :open-menu false}) + (fn [] + (-> (or (get @session-filters* file-id) + {:term "" + :section "all"}) + (assoc :ordering (dwa/get-current-assets-ordering) + :list-style (dwa/get-current-assets-list-style) + :open-menu false)))) filters (deref filters*) term (:term filters) list-style (:list-style filters) @@ -162,6 +170,9 @@ :id "typographies" :handler on-section-filter-change}])] + (mf/with-effect [file-id term section] + (swap! session-filters* assoc file-id {:term term :section section})) + [:article {:class (stl/css :assets-bar)} [:div {:class (stl/css :assets-header)} (when-not ^boolean read-only?