From 8e02dced2f420936abe6885e557a540989ac43bd Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 19 Aug 2024 10:49:46 +0200 Subject: [PATCH] Extract to function --- frontend/src/app/main/refs.cljs | 3 +++ .../src/app/main/ui/workspace/tokens/sidebar.cljs | 8 +------- .../src/app/main/ui/workspace/tokens/token_set.cljs | 11 +++++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 777592dd2..3772523cc 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -243,6 +243,9 @@ (def workspace-active-theme-ids (l/derived wtts/get-active-theme-ids st/state)) +(def workspace-active-set-ids + (l/derived wtts/get-active-set-ids 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 709d1fbd1..f61744058 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -170,14 +170,8 @@ [_props] (let [active-theme-ids (mf/deref refs/workspace-active-theme-ids) themes (mf/deref refs/workspace-ordered-token-themes) - themes-index (mf/deref refs/workspace-token-themes) - 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) + active-set-ids (mf/deref refs/workspace-active-set-ids) token-sets (mf/deref refs/workspace-token-sets)] [:div [:style 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 5d4410d29..d9eec5ff8 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs @@ -25,6 +25,17 @@ (defn get-temp-theme-id [state] (get-in state [:workspace-data :token-theme-temporary-id])) +(defn get-active-set-ids [state] + (let [active-theme-ids (get-active-theme-ids state) + themes-index (get-workspace-themes-index state) + active-set-ids (reduce + (fn [acc cur] + (if-let [sets (get-in themes-index [cur :sets])] + (set/union acc sets) + acc)) + #{} active-theme-ids)] + active-set-ids)) + (defn theme-ids-with-group "Returns set of theme-ids that share the same `:group` property as the theme with `theme-id`. Will also return matching theme-ids without a `:group` property."