🔥 Remove not necessary API from tokens-lib: add-sets

This commit is contained in:
Andrey Antukh 2025-03-14 16:48:31 +01:00
parent 802c67ace4
commit 1e10e3818e
5 changed files with 29 additions and 41 deletions

View file

@ -376,11 +376,6 @@
[:type [:= :update-active-token-themes]] [:type [:= :update-active-token-themes]]
[:theme-ids [:set :string]]]] [:theme-ids [:set :string]]]]
[:add-token-sets
[:map {:title "AddTokenSetsChange"}
[:type [:= :add-token-sets]]
[:token-sets [:sequential ::ctot/token-set]]]]
[:rename-token-set-group [:rename-token-set-group
[:map {:title "RenameTokenSetGroup"} [:map {:title "RenameTokenSetGroup"}
[:type [:= :rename-token-set-group]] [:type [:= :rename-token-set-group]]
@ -1049,12 +1044,6 @@
(update data :tokens-lib #(-> % (ctob/ensure-tokens-lib) (update data :tokens-lib #(-> % (ctob/ensure-tokens-lib)
(ctob/set-active-themes theme-ids)))) (ctob/set-active-themes theme-ids))))
(defmethod process-change :add-token-sets
[data {:keys [token-sets]}]
(update data :tokens-lib #(-> %
(ctob/ensure-tokens-lib)
(ctob/add-sets (map ctob/make-token-set token-sets)))))
(defmethod process-change :rename-token-set-group (defmethod process-change :rename-token-set-group
[data {:keys [set-group-path set-group-fname]}] [data {:keys [set-group-path set-group-fname]}]
(update data :tokens-lib (fn [lib] (update data :tokens-lib (fn [lib]

View file

@ -430,7 +430,6 @@
Prefixed set full path or pfpath: a full path wit prefixes [\"G-some-group\", \"G-some-subgroup\", \"S-some-set\"]. Prefixed set full path or pfpath: a full path wit prefixes [\"G-some-group\", \"G-some-subgroup\", \"S-some-set\"].
Prefixed set final name or pfname: a final name with prefix \"S-some-set\"." Prefixed set final name or pfname: a final name with prefix \"S-some-set\"."
(add-set [_ token-set] "add a set to the library, at the end") (add-set [_ token-set] "add a set to the library, at the end")
(add-sets [_ token-set] "add a collection of sets to the library, at the end")
(update-set [_ set-name f] "modify a set in the library") (update-set [_ set-name f] "modify a set in the library")
(delete-set-path [_ set-path] "delete a set in the library") (delete-set-path [_ set-path] "delete a set in the library")
(delete-set [_ set-name] "delete a set at `set-name` in the library and disable the `set-name` in all themes") (delete-set [_ set-name] "delete a set at `set-name` in the library and disable the `set-name` in all themes")
@ -875,9 +874,6 @@ Will return a value that matches this schema:
themes themes
active-themes))) active-themes)))
(add-sets [this token-sets]
(reduce add-set this token-sets))
(update-set [this set-name f] (update-set [this set-name f]
(let [prefixed-full-path (set-name->prefixed-full-path set-name) (let [prefixed-full-path (set-name->prefixed-full-path set-name)
set (get-in sets prefixed-full-path)] set (get-in sets prefixed-full-path)]
@ -1483,10 +1479,12 @@ Will return a value that matches this schema:
prev-sets (->> (fres/read-object! r) prev-sets (->> (fres/read-object! r)
(tree-seq d/ordered-map? vals) (tree-seq d/ordered-map? vals)
(filter (partial instance? TokenSet))) (filter (partial instance? TokenSet)))
sets (-> (make-tokens-lib)
(add-sets prev-sets) ;; FIXME: wtf we usind deref here?
sets (-> (reduce add-set (make-tokens-lib) prev-sets)
(deref) (deref)
:sets) (:sets))
_set-groups (fres/read-object! r) _set-groups (fres/read-object! r)
themes (fres/read-object! r) themes (fres/read-object! r)
active-themes (fres/read-object! r)] active-themes (fres/read-object! r)]

View file

@ -139,7 +139,7 @@
(let [data (dsh/lookup-file-data state) (let [data (dsh/lookup-file-data state)
tokens-lib (get data :tokens-lib) tokens-lib (get data :tokens-lib)
set-name (ctob/normalize-set-name set-name)] set-name (ctob/normalize-set-name set-name)]
(if (ctob/get-set tokens-lib set-name) (if (and tokens-lib (ctob/get-set tokens-lib set-name))
(rx/of (ntf/show {:content (tr "errors.token-set-already-exists") (rx/of (ntf/show {:content (tr "errors.token-set-already-exists")
:type :toast :type :toast
:level :error :level :error

View file

@ -293,11 +293,12 @@
:on-save-form on-save-form :on-save-form on-save-form
:disabled? disabled?}]]]]])) :disabled? disabled?}]]]]]))
(defn- make-lib-with-theme [theme sets] (defn- make-lib-with-theme
(-> (ctob/make-tokens-lib) [theme sets]
(ctob/add-theme theme) (let [tlib (-> (ctob/make-tokens-lib)
(ctob/add-sets sets) (ctob/add-theme theme))
(ctob/activate-theme (:group theme) (:name theme)))) tlib (reduce ctob/add-set tlib sets)]
(ctob/activate-theme tlib (:group theme) (:name theme))))
(mf/defc controlled-edit-theme (mf/defc controlled-edit-theme
[{:keys [state set-state]}] [{:keys [state set-state]}]