From 97436531d080abc70e035d80e56e49acbfb85e95 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 19 Aug 2024 10:46:48 +0200 Subject: [PATCH] Showing only active sets --- frontend/src/app/main/data/tokens.cljs | 3 ++- frontend/src/app/main/refs.cljs | 3 --- .../src/app/main/ui/workspace/tokens/sidebar.cljs | 13 +++++++++---- .../src/app/main/ui/workspace/tokens/token_set.cljs | 7 +++++++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index db83f9e33..0fae9ee93 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -163,7 +163,8 @@ changes (-> (pcb/empty-changes it) (pcb/update-token-theme (wtts/toggle-token-set-to-token-theme token-set-id theme) - theme))] + theme) + (pcb/update-active-token-themes #{(wtts/update-theme-id state)} (wtts/get-active-theme-ids state)))] (rx/of (dch/commit-changes changes)))))) (defn delete-token-set [token-set-id] diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 77a5e9490..777592dd2 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -243,9 +243,6 @@ (def workspace-active-theme-ids (l/derived wtts/get-active-theme-ids st/state)) -(def workspace-active-theme-id - (l/derived wtts/update-theme-id st/state)) - (def workspace-token-themes (l/derived wtts/get-workspace-themes-index st/state)) diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 1a3f63754..709d1fbd1 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -28,7 +28,8 @@ [cuerdas.core :as str] [okulary.core :as l] [rumext.v2 :as mf] - [shadow.resource])) + [shadow.resource] + [clojure.set :as set])) (def lens:token-type-open-status (l/derived (l/in [:workspace-tokens :open-status]) st/state)) @@ -168,10 +169,14 @@ (mf/defc token-sets [_props] (let [active-theme-ids (mf/deref refs/workspace-active-theme-ids) - selected-theme-id (mf/deref refs/workspace-active-theme-id) themes (mf/deref refs/workspace-ordered-token-themes) themes-index (mf/deref refs/workspace-token-themes) - selected-theme (get themes-index selected-theme-id) + active-set-ids (reduce + (fn [acc cur] + (if-let [sets (get-in themes-index [cur :sets])] + (set/union acc sets) + acc)) + #{} active-theme-ids) selected-token-set-id (mf/deref refs/workspace-selected-token-set-id) token-sets (mf/deref refs/workspace-token-sets)] [:div @@ -234,7 +239,7 @@ (dom/prevent-default e) (dom/stop-propagation e) (st/emit! (wdt/toggle-token-set id)))} - (when (wtts/token-set-enabled-in-theme? id selected-theme) "👁️")] + (when (get active-set-ids id) "👁️")] [:button {:on-click (fn [e] (dom/prevent-default e) (dom/stop-propagation e) diff --git a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs index 7d7a432b8..5d4410d29 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs @@ -59,6 +59,13 @@ (or temp-theme-id-set #{}) new-themes))) +(defn get-active-theme-ids-or-temp-theme-id + [state] + (let [active-theme-ids (get-active-theme-ids state)] + (if (seq active-theme-ids) + active-theme-ids + (get-temp-theme-id state)))) + (defn update-theme-id [state] (let [active-themes (get-active-theme-ids state)