From a9aac4c8672207ca1d99af318c0f5eb0918348f0 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 25 Apr 2024 19:00:00 +0200 Subject: [PATCH] Move emit to the shape update function [*] [*] A shape update might need multiple emit functions --- .../app/main/ui/workspace/tokens/core.cljs | 34 ++++++++++--------- .../app/main/ui/workspace/tokens/sidebar.cljs | 6 ++-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index be3e51955..57231f702 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -30,27 +30,29 @@ ;; Update functions ------------------------------------------------------------ (defn update-shape-radius [value shape-ids] - (let [parsed-value (d/parse-integer value)] - (dch/update-shapes shape-ids - (fn [shape] - (when (ctsr/has-radius? shape) - (ctsr/set-radius-1 shape parsed-value))) - {:reg-objects? true - :attrs ctt/border-radius-keys}))) + (st/emit! + (dch/update-shapes shape-ids + (fn [shape] + (when (ctsr/has-radius? shape) + (ctsr/set-radius-1 shape value))) + {:reg-objects? true + :attrs ctt/border-radius-keys}))) ;; Token types ----------------------------------------------------------------- (def token-types (ordered-map - [:boolean {:title "Boolean" - :modal {:key :tokens/boolean - :fields [{:label "Boolean"}]}}] - [:border-radius {:title "Border Radius" - :attributes ctt/border-radius-keys - :modal {:key :tokens/border-radius - :fields [{:label "Border Radius" - :key :border-radius}]} - :on-update-shape update-shape-radius}] + [:boolean + {:title "Boolean" + :modal {:key :tokens/boolean + :fields [{:label "Boolean"}]}}] + [:border-radius + {:title "Border Radius" + :attributes ctt/border-radius-keys + :on-update-shape update-shape-radius + :modal {:key :tokens/border-radius + :fields [{:label "Border Radius" + :key :border-radius}]}}] [:box-shadow {:title "Box Shadow" :modal {:key :tokens/box-shadow diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index cf16a3fd5..5e8a7baa5 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.workspace.tokens.sidebar (:require-macros [app.main.style :as stl]) (:require + [app.common.data :as d] [app.main.data.modal :as modal] [app.main.data.tokens :as dt] [app.main.refs :as refs] @@ -25,12 +26,13 @@ shape-ids (->> selected-shapes (eduction (remove #(tokens-applied? token % attributes)) - (map :id)))] + (map :id))) + token-value (d/parse-integer (:value token))] (doseq [shape selected-shapes] (st/emit! (on-apply {:token-id (:id token) :shape-id (:id shape) :attributes attributes})) - (st/emit! (on-update-shape (:value token) shape-ids))))) + (on-update-shape token-value shape-ids)))) (mf/defc token-pill {::mf/wrap-props false}