From 52def43f5accd79d6a76348098ab5a5b3fb0a781 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 28 Feb 2022 15:46:11 +0100 Subject: [PATCH] :bug: Fix issue with react hooks --- frontend/src/app/main/ui/shapes/attrs.cljs | 5 ++-- .../src/app/main/ui/shapes/custom_stroke.cljs | 23 ++++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/frontend/src/app/main/ui/shapes/attrs.cljs b/frontend/src/app/main/ui/shapes/attrs.cljs index dfe08205e..e1c01012f 100644 --- a/frontend/src/app/main/ui/shapes/attrs.cljs +++ b/frontend/src/app/main/ui/shapes/attrs.cljs @@ -233,9 +233,8 @@ (obj/set! "style" fill-styles)))) (defn extract-stroke-attrs - [shape index] - (let [render-id (mf/use-ctx muc/render-ctx) - stroke-styles (-> (obj/get shape "style" (obj/new)) + [shape index render-id] + (let [stroke-styles (-> (obj/get shape "style" (obj/new)) (add-stroke shape render-id index))] (-> (obj/new) (obj/set! "style" stroke-styles)))) diff --git a/frontend/src/app/main/ui/shapes/custom_stroke.cljs b/frontend/src/app/main/ui/shapes/custom_stroke.cljs index eec58ff19..3eaca2883 100644 --- a/frontend/src/app/main/ui/shapes/custom_stroke.cljs +++ b/frontend/src/app/main/ui/shapes/custom_stroke.cljs @@ -316,9 +316,8 @@ [:& stroke-defs {:shape shape :render-id render-id :index index}]] child]))) -(defn build-stroke-props [position shape child value] - (let [render-id (mf/use-ctx muc/render-ctx) - url-fill? (or (some? (:fill-image shape)) +(defn build-stroke-props [position shape child value render-id] + (let [url-fill? (or (some? (:fill-image shape)) (= :image (:type shape)) (> (count (:fills shape)) 1) (some :fill-color-gradient (:fills shape))) @@ -348,23 +347,25 @@ (obj/set! "fillOpacity" "none"))))) props (-> props - (add-style - (obj/get (attrs/extract-stroke-attrs value position) "style")))] + (add-style (obj/get (attrs/extract-stroke-attrs value position render-id) "style")))] props)) (mf/defc shape-custom-strokes {::mf/wrap-props false} [props] - (let [child (obj/get props "children") - shape (obj/get props "shape") - elem-name (obj/get child "type")] + (let [child (obj/get props "children") + shape (obj/get props "shape") + elem-name (obj/get child "type") + render-id (mf/use-ctx muc/render-ctx)] (cond - (seq (:strokes shape)) + (d/not-empty? (:strokes shape)) [:* (for [[index value] (-> (d/enumerate (:strokes shape)) reverse)] - [:& shape-custom-stroke {:shape (assoc value :points (:points shape)) :index index} - [:> elem-name (build-stroke-props index shape child value)]])] + (let [props (build-stroke-props index shape child value render-id) + shape (assoc value :points (:points shape))] + [:& shape-custom-stroke {:shape shape :index index} + [:> elem-name props]]))] :else [:& shape-custom-stroke {:shape shape :index 0}