diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 72f2cb5ad..5f6c71e1e 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -155,6 +155,13 @@ shape-after-token-3-is-applied) nil) +(defn set-token-type-section-open + [token-type open?] + (ptk/reify ::set-token-type-section-open + ptk/UpdateEvent + (update [_ state] + (assoc-in state [:workspace-tokens :open-status token-type] open?)))) + ;; Token Context Menu Functions ------------------------------------------------- (defn show-token-context-menu diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 015d2635f..0cce5fbdf 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -16,8 +16,12 @@ [app.main.ui.workspace.sidebar.assets.common :as cmm] [app.main.ui.workspace.tokens.core :as wtc] [app.util.dom :as dom] + [okulary.core :as l] [rumext.v2 :as mf])) +(def lens:token-type-open-status + (l/derived (l/in [:workspace-tokens :open-status]) st/state)) + (mf/defc token-pill {::mf/wrap-props false} [{:keys [on-click token highlighted? on-context-menu]}] @@ -53,7 +57,8 @@ (mf/defc token-component [{:keys [type tokens selected-shapes token-type-props]}] - (let [open? (mf/use-state false) + (let [open? (mf/deref (-> (l/key type) + (l/derived lens:token-type-open-status))) {:keys [modal attributes title]} token-type-props on-context-menu (mf/use-fn @@ -66,8 +71,7 @@ on-toggle-open-click (mf/use-fn (mf/deps open? tokens) - #(when (seq tokens) - (swap! open? not))) + #(st/emit! (dt/set-token-type-section-open type (not open?)))) on-popover-open-click (mf/use-fn (fn [event] (let [{:keys [key fields]} modal] @@ -93,7 +97,7 @@ :title title :assets-count tokens-count - :open? @open?} + :open? open?} [:& cmm/asset-section-block {:role :title-button} [:button {:class (stl/css :action-button) :on-click on-popover-open-click}