mirror of
https://github.com/penpot/penpot.git
synced 2026-09-11 06:28:47 +00:00
✨ 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:
parent
6788df02ca
commit
68595e90eb
@ -64,6 +64,7 @@
|
|||||||
|
|
||||||
- Access Tokens look & feel refinement [Taiga #13114](https://tree.taiga.io/project/penpot/us/13114)
|
- 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)
|
- 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
|
### :bug: Bugs fixed
|
||||||
|
|
||||||
|
|||||||
@ -70,16 +70,24 @@
|
|||||||
[v a b]
|
[v a b]
|
||||||
(if (= v a) b a))
|
(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/defc assets-toolbox*
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
[{:keys [size file-id]}]
|
[{:keys [size file-id]}]
|
||||||
(let [read-only? (mf/use-ctx ctx/workspace-read-only?)
|
(let [read-only? (mf/use-ctx ctx/workspace-read-only?)
|
||||||
filters* (mf/use-state
|
filters* (mf/use-state
|
||||||
{:term ""
|
(fn []
|
||||||
:section "all"
|
(-> (or (get @session-filters* file-id)
|
||||||
:ordering (dwa/get-current-assets-ordering)
|
{:term ""
|
||||||
:list-style (dwa/get-current-assets-list-style)
|
:section "all"})
|
||||||
:open-menu false})
|
(assoc :ordering (dwa/get-current-assets-ordering)
|
||||||
|
:list-style (dwa/get-current-assets-list-style)
|
||||||
|
:open-menu false))))
|
||||||
filters (deref filters*)
|
filters (deref filters*)
|
||||||
term (:term filters)
|
term (:term filters)
|
||||||
list-style (:list-style filters)
|
list-style (:list-style filters)
|
||||||
@ -162,6 +170,9 @@
|
|||||||
:id "typographies"
|
:id "typographies"
|
||||||
:handler on-section-filter-change}])]
|
: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)}
|
[:article {:class (stl/css :assets-bar)}
|
||||||
[:div {:class (stl/css :assets-header)}
|
[:div {:class (stl/css :assets-header)}
|
||||||
(when-not ^boolean read-only?
|
(when-not ^boolean read-only?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user