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 <meobius123@gmail.com>
Co-authored-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
Dream 2026-04-14 06:31:25 -04:00 committed by GitHub
parent 6788df02ca
commit 68595e90eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

View File

@ -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

View File

@ -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?