From 48c85d72002a1a2023c1774c13c3a2075c585b55 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 16 May 2024 09:55:57 +0200 Subject: [PATCH] Simplify token application --- frontend/src/app/main/data/tokens.cljs | 15 +++++++++++++-- .../workspace/sidebar/options/menus/measures.cljs | 10 +++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index b960a4369..fce743303 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -59,10 +59,21 @@ (let [token (token-from-attributes token-id attributes)] (toggle-or-apply-token shape token))) -(defn apply-token-to-shape [{:keys [shape _token-id _attributes] :as props}] - (let [applied-tokens (apply-token-id-to-attributes props)] +(defn apply-token-to-shape + "When the passed `:token` is non-nil apply it to the `:applied-tokens` on a shape." + [{:keys [shape token attributes] :as props}] + (let [applied-tokens (apply-token-id-to-attributes {:shape shape + :token-id (:id token) + :attributes attributes})] (update shape :applied-tokens #(merge % applied-tokens)))) +(defn maybe-apply-token-to-shape + "When the passed `:token` is non-nil apply it to the `:applied-tokens` on a shape." + [{:keys [shape token _attributes] :as props}] + (if token + (apply-token-to-shape props) + shape)) + (defn update-token-from-attributes [{:keys [token-id shape-id attributes]}] (ptk/reify ::update-token-from-attributes diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs index fd942ffe6..7350b15ce 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs @@ -296,11 +296,11 @@ token-value (some-> token wtc/resolve-token-value)] (st/emit! (change-radius (fn [shape] - (cond-> shape - token-value (#(dt/apply-token-to-shape {:token-id (:id token) - :shape % - :attributes (wtc/token-attributes :border-radius)})) - :always (ctsr/set-radius-1 (or token-value value))))))))) + (-> (dt/maybe-apply-token-to-shape + {:token-id token + :shape shape + :attributes (wtc/token-attributes :border-radius)}) + (ctsr/set-radius-1 (or token-value value))))))))) on-radius-multi-change (mf/use-fn