From f1f2767e2a872e2adf2ce143005a1cb9c8f979f4 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 1 Oct 2024 12:49:03 +0200 Subject: [PATCH] Activating initial sets by adding them to the token theme --- common/src/app/common/types/tokens_lib.cljc | 7 +++++++ frontend/src/app/main/data/tokens.cljs | 23 +++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index efe84abf6..2b355a249 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -273,6 +273,7 @@ (def hidden-token-theme-path (token-theme-path hidden-token-theme-group hidden-token-theme-name)) + (defprotocol ITokenTheme (set-sets [_ set-names] "set the active token sets") (toggle-set [_ set-name] "togle a set used / not used in the theme") @@ -347,6 +348,12 @@ token-theme)) +(defn make-hidden-token-theme + [& {:keys [] :as params}] + (make-token-theme (assoc params + :group hidden-token-theme-group + :name hidden-token-theme-name))) + ;; === TokenThemes (collection) (defprotocol ITokenThemes diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index bbd355337..0100f8360 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -182,10 +182,7 @@ active-token-set-names (ctob/get-active-themes-set-names tokens-lib) theme (-> (or (some-> prev-theme (ctob/set-sets active-token-set-names)) - (ctob/make-token-theme - :group ctob/hidden-token-theme-group - :name ctob/hidden-token-theme-name - :sets active-token-set-names)) + (ctob/make-hidden-token-theme :sets active-token-set-names)) (ctob/toggle-set token-set-name)) prev-active-token-themes (ctob/get-active-theme-paths tokens-lib) changes (-> (pcb/empty-changes it) @@ -218,8 +215,22 @@ token-set-name (or (:name token-set) "Global") changes (if (not token-set) ;; No set created add a global set - (->> (ctob/make-token-set :name token-set-name :tokens {(:name token) token}) - (pcb/add-token-set (pcb/empty-changes))) + (let [tokens-lib (get-tokens-lib state) + token-set (ctob/make-token-set :name token-set-name :tokens {(:name token) token}) + hidden-theme (ctob/make-hidden-token-theme :sets [token-set-name]) + active-theme-paths (some-> tokens-lib ctob/get-active-theme-paths) + add-to-hidden-theme? (= active-theme-paths #{ctob/hidden-token-theme-path}) + base-changes (pcb/add-token-set (pcb/empty-changes) token-set)] + (cond + (not tokens-lib) (-> base-changes + (pcb/add-token-theme hidden-theme) + (pcb/update-active-token-themes #{ctob/hidden-token-theme-path} #{})) + + add-to-hidden-theme? (let [prev-hidden-theme (ctob/get-theme tokens-lib ctob/hidden-token-theme-group ctob/hidden-token-theme-name)] + (-> base-changes + (pcb/update-token-theme (ctob/toggle-set prev-hidden-theme ctob/hidden-token-theme-path) prev-hidden-theme))) + + :else base-changes)) ;; Either update or add token to existing set (if-let [prev-token (ctob/get-token token-set (or prev-token-name (:name token)))] (pcb/update-token (pcb/empty-changes) (:name token-set) token prev-token)