diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 927f7ee8c..6dd036778 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -16,6 +16,14 @@ [cuerdas.core :as str] #?(:clj [app.common.fressian :as fres]))) +;; === Constants + +(def hidden-token-theme-group + "") + +(def hidden-token-theme-name + "__PENPOT__HIDDEN__TOKEN__THEME__") + ;; === Groups handling (def schema:groupable-item @@ -257,7 +265,9 @@ (defprotocol ITokenTheme (toggle-set [_ set-name] "togle a set used / not used in the theme") - (theme-path [_] "get `token-theme-path` from theme")) + (theme-path [_] "get `token-theme-path` from theme") + (theme-matches-group-name [_ group name] "if a theme matches the given group & name") + (hidden-temporary-theme? [_] "if a theme is the (from the user ui) hidden temporary theme")) (defrecord TokenTheme [name group description is-source modified-at sets] ITokenTheme @@ -271,7 +281,14 @@ (disj sets set-name) (conj sets set-name)))) (theme-path [_] - (token-theme-path group name))) + (token-theme-path group name)) + + (theme-matches-group-name [this group name] + (and (= (:group this) group) + (= (:name this) name))) + + (hidden-temporary-theme? [this] + (theme-matches-group-name this hidden-token-theme-group hidden-token-theme-name))) (def schema:token-theme [:and [:map {:title "TokenTheme"} diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 10c9f33d2..6a33024a2 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -48,12 +48,6 @@ (defn get-tokens-lib [state] (get-in state [:workspace-data :tokens-lib])) -(def hidden-token-theme-group - "") - -(def hidden-token-theme-name - "__PENPOT__HIDDEN__TOKEN__SET__") - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; TOKENS Actions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -222,14 +216,14 @@ ptk/WatchEvent (watch [it state _] (let [tokens-lib (get-tokens-lib state) - prev-theme (ctob/get-theme tokens-lib hidden-token-theme-group hidden-token-theme-name) + prev-theme (ctob/get-theme tokens-lib ctob/hidden-token-theme-group ctob/hidden-token-theme-name) theme (-> (or prev-theme (ctob/make-token-theme - :group hidden-token-theme-group - :name hidden-token-theme-name)) + :group ctob/hidden-token-theme-group + :name ctob/hidden-token-theme-name)) (ctob/toggle-set token-set-name)) prev-active-token-themes (ctob/get-active-theme-paths tokens-lib) changes (-> (pcb/empty-changes it) - (pcb/update-active-token-themes #{(ctob/token-theme-path hidden-token-theme-group hidden-token-theme-name)} prev-active-token-themes)) + (pcb/update-active-token-themes #{(ctob/token-theme-path ctob/hidden-token-theme-group ctob/hidden-token-theme-name)} prev-active-token-themes)) changes' (if prev-theme (pcb/update-token-theme changes theme prev-theme) (pcb/add-token-theme changes theme))] diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 2e460ffb0..1bf96a760 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -465,6 +465,9 @@ (def workspace-token-themes (l/derived #(or (some-> % ctob/get-themes) []) tokens-lib)) +(def workspace-token-themes-no-hidden + (l/derived #(remove ctob/hidden-temporary-theme? %) workspace-token-themes)) + (def workspace-selected-token-set-id (l/derived wtts/get-selected-token-set-id st/state)) diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index afc1d0c4f..24bd15bf0 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -241,7 +241,7 @@ (mf/defc themes [_] - (let [themes (mf/deref refs/workspace-token-themes) + (let [themes (mf/deref refs/workspace-token-themes-no-hidden) state (mf/use-state (if (empty? themes) {:type :create-theme} {:type :themes-overview}))