diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 0d848f197..fca19bc28 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -258,7 +258,7 @@ [:update-active-token-themes [:map {:title "UpdateActiveTokenThemes"} [:type [:= :update-active-token-themes]] - [:theme-ids [:set ::sm/uuid]]]] + [:theme-ids [:set :string]]]] [:delete-temporary-token-theme [:map {:title "DeleteTemporaryTokenThemeChange"} @@ -846,7 +846,10 @@ (defmethod process-change :update-active-token-themes [data {:keys [theme-ids]}] - (ctotl/assoc-active-token-themes data theme-ids)) + (-> data + (update :tokens-lib #(-> % + (ctob/ensure-tokens-lib) + (ctob/set-active-themes theme-ids))))) (defmethod process-change :delete-temporary-token-theme [data {:keys [id group name]}] diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index a2e1e2ddf..5dd6e2a53 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -328,6 +328,7 @@ (get-theme-groups [_] "get a sequence of group names by order") (get-active-theme-paths [_] "get the active theme paths") (get-active-themes [_] "get an ordered sequence of active themes in the library") + (set-active-themes [_ active-themes] "set active themes in library") (theme-active? [_ group name] "predicate if token theme is active") (activate-theme [_ group name] "adds theme from the active-themes") (deactivate-theme [_ group name] "removes theme from the active-themes") @@ -489,6 +490,12 @@ (get-theme [_ group name] (dm/get-in themes [group name])) + (set-active-themes [_ active-themes] + (TokensLib. sets + set-groups + themes + active-themes)) + (activate-theme [this group name] (if-let [theme (get-theme this group name)] (let [group-themes (->> (get themes group) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 495c1f98c..fb0fd0ee0 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -140,17 +140,19 @@ theme)) :else changes))) -(defn toggle-token-theme [token-theme-id] - (ptk/reify ::toggle-token-theme +(defn toggle-token-theme-active? [group name] + (ptk/reify ::toggle-token-theme-active? ptk/WatchEvent (watch [it state _] - (let [themes (wtts/get-active-theme-ids state) - new-themes (wtts/toggle-active-theme-id token-theme-id state) - changes (-> (pcb/empty-changes it) - (pcb/update-active-token-themes new-themes themes))] + (let [tokens-lib (get-tokens-lib state) + prev-active-token-themes (some-> tokens-lib + (ctob/get-active-theme-paths)) + active-token-themes (some-> tokens-lib + (ctob/toggle-theme-active? group name) + (ctob/get-active-theme-paths)) + changes (pcb/update-active-token-themes (pcb/empty-changes it) active-token-themes prev-active-token-themes)] (rx/of - (dch/commit-changes changes) - (wtu/update-workspace-tokens)))))) + (dch/commit-changes changes)))))) (defn delete-token-theme [token-theme-id] (ptk/reify ::delete-token-theme diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 6650c4828..e8b0b7b32 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -471,10 +471,10 @@ (def workspace-ordered-token-sets (l/derived #(or (some-> % ctob/get-sets) []) tokens-lib)) -(dm/legacy - (def workspace-active-theme-ids - (l/derived wtts/get-active-theme-ids st/state)) +(def workspace-active-theme-paths + (l/derived #(some-> % ctob/get-active-theme-paths) tokens-lib)) +(dm/legacy (def workspace-temp-theme-id (l/derived wtts/get-temp-theme-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 0dc6fcb57..c992ef46c 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.workspace.tokens.modals.themes (:require-macros [app.main.style :as stl]) (:require + [app.common.types.tokens-lib :as ctob] [app.main.data.modal :as modal] [app.main.data.tokens :as wdt] [app.main.refs :as refs] @@ -55,7 +56,7 @@ (mf/defc themes-overview [{:keys [set-state]}] - (let [active-theme-ids (mf/deref refs/workspace-active-theme-ids) + (let [active-theme-ids (mf/deref refs/workspace-active-theme-paths) themes-groups (mf/deref refs/workspace-token-theme-tree) on-edit-theme (fn [theme e] (dom/prevent-default e) @@ -69,15 +70,15 @@ (when (seq group) [:span {:class (stl/css :theme-group-label)} group]) [:ul {:class (stl/css :theme-group-rows-wrapper)} - (for [[_ {:keys [id name] :as theme}] themes - :let [selected? (some? (get active-theme-ids id))]] + (for [[_ {:keys [id group name] :as theme}] themes + :let [selected? (some? (get active-theme-ids (ctob/theme-path theme)))]] [:li {:key (str "token-theme-" id) :class (stl/css :theme-row)} [:div {:class (stl/css :theme-row-left)} [:div {:on-click (fn [e] (dom/prevent-default e) (dom/stop-propagation e) - (st/emit! (wdt/toggle-token-theme id)))} + (st/emit! (wdt/toggle-token-theme-active? group name)))} [:& switch {:name (str "Theme" name) :on-change (constantly nil) :selected? selected?}]] diff --git a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs index 09ab604d2..49b169a78 100644 --- a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs @@ -8,6 +8,7 @@ (:require-macros [app.main.style :as stl]) (:require [app.common.data.macros :as dm] + [app.common.types.tokens-lib :as ctob] [app.common.uuid :as uuid] [app.main.data.modal :as modal] [app.main.data.tokens :as wdt] @@ -22,8 +23,8 @@ [{:keys [themes active-theme-ids on-close grouped?]}] (when (seq themes) [:ul - (for [[_ {:keys [id name]}] themes - :let [selected? (get active-theme-ids id)]] + (for [[_ {:keys [id group name] :as theme}] themes + :let [selected? (get active-theme-ids (ctob/theme-path theme))]] [:li {:key id :class (stl/css-case :checked-element true @@ -31,14 +32,14 @@ :is-selected selected?) :on-click (fn [e] (dom/stop-propagation e) - (st/emit! (wdt/toggle-token-theme id)) + (st/emit! (wdt/toggle-token-theme-active? group name)) (on-close))} [:span {:class (stl/css :label)} name] [:span {:class (stl/css :check-icon)} i/tick]])])) (mf/defc theme-options [{:keys [on-close]}] - (let [active-theme-ids (dm/fixme (mf/deref refs/workspace-active-theme-ids)) + (let [active-theme-ids (dm/fixme (mf/deref refs/workspace-active-theme-paths)) theme-groups (mf/deref refs/workspace-token-theme-tree)] [:ul (for [[group themes] theme-groups] @@ -59,7 +60,7 @@ [{:keys []}] (let [;; Store temp-theme-id (dm/legacy (mf/deref refs/workspace-temp-theme-id)) - active-theme-ids (dm/legacy (-> (mf/deref refs/workspace-active-theme-ids) + active-theme-ids (dm/legacy (-> (mf/deref refs/workspace-active-theme-paths) (disj temp-theme-id))) active-themes-count (count active-theme-ids) themes (mf/deref refs/workspace-token-theme-tree)