🐛 Fixes after review

This commit is contained in:
alonso.torres 2022-04-22 11:29:22 +02:00
parent dfc9d0709d
commit a82bcd0ab2
9 changed files with 30 additions and 32 deletions

View file

@ -512,10 +512,11 @@
id-duplicated (first new-selected)] id-duplicated (first new-selected)]
;; Warning: This order is important for the focus mode. (rx/concat
(rx/merge
(->> (rx/from dup-frames) (->> (rx/from dup-frames)
(rx/map (fn [[old-id new-id]] (dwt/duplicate-thumbnail old-id new-id)))) (rx/map (fn [[old-id new-id]] (dwt/duplicate-thumbnail old-id new-id))))
;; Warning: This order is important for the focus mode.
(rx/of (dch/commit-changes changes) (rx/of (dch/commit-changes changes)
(select-shapes new-selected) (select-shapes new-selected)
(memorize-duplicated id-original id-duplicated)))))))))) (memorize-duplicated id-original id-duplicated))))))))))

View file

@ -7,6 +7,7 @@
(ns app.main.data.workspace.thumbnails (ns app.main.data.workspace.thumbnails
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages.helpers :as cph]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.refs :as refs] [app.main.refs :as refs]
@ -49,17 +50,15 @@
;; the 2 second debounce is finished ;; the 2 second debounce is finished
(rx/merge (rx/merge
(->> stream (->> stream
(rx/take-until stopper)
(rx/filter (ptk/type? ::update-thumbnail)) (rx/filter (ptk/type? ::update-thumbnail))
(rx/filter #(= id (:id (deref %)))) (rx/map deref)
(rx/filter #(= id (:id %)))
(rx/debounce 2000) (rx/debounce 2000)
(rx/first) (rx/take 1)
(rx/flat-map (rx/map :data)
(fn [event] (rx/flat-map #(rp/mutation! :upsert-file-object-thumbnail (assoc params :data %)))
(let [data (:data @event)] (rx/map #(fn [state] (d/dissoc-in state [::update-thumbnail-lock id])))
(rp/mutation! :upsert-file-object-thumbnail (assoc params :data data))))) (rx/take-until stopper))
(rx/map #(fn [state] (d/dissoc-in state [::update-thumbnail-lock id]))))
(->> (rx/of (update-thumbnail id data)) (->> (rx/of (update-thumbnail id data))
(rx/observe-on :async))))))))) (rx/observe-on :async)))))))))
@ -98,9 +97,7 @@
(fn [id] (fn [id]
(let [shape (or (get new-objects id) (let [shape (or (get new-objects id)
(get old-objects id))] (get old-objects id))]
(or (and (cph/frame-shape? shape) id) (:frame-id shape))))
(or (and (= :frame (:type shape)) id)
(:frame-id shape))))
;; Extracts the frames and then removes nils and the root frame ;; Extracts the frames and then removes nils and the root frame
xform (comp (mapcat extract-ids) xform (comp (mapcat extract-ids)
@ -151,17 +148,17 @@
;; Async so we wait for additional side-effects of commit-changes ;; Async so we wait for additional side-effects of commit-changes
(rx/observe-on :async) (rx/observe-on :async)
(rx/filter (comp not thumbnail-change?)) (rx/filter (complement thumbnail-change?))
(rx/with-latest-from objects-stream) (rx/with-latest-from objects-stream)
(rx/map extract-frame-changes) (rx/map extract-frame-changes)
(rx/share))] (rx/share))]
(->> frame-changes (->> frame-changes
(rx/take-until stopper)
(rx/flat-map (rx/flat-map
(fn [ids] (fn [ids]
(->> (rx/from ids) (->> (rx/from ids)
(rx/map #(ptk/data-event ::force-render %)))))))))) (rx/map #(ptk/data-event ::force-render %)))))
(rx/take-until stopper))))))
(defn duplicate-thumbnail (defn duplicate-thumbnail
[old-id new-id] [old-id new-id]

View file

@ -396,7 +396,7 @@
st/state)) st/state))
(def thumbnail-data (def thumbnail-data
(l/derived #(get-in % [:workspace-file :thumbnails] {}) st/state)) (l/derived #(dm/get-in % [:workspace-file :thumbnails] {}) st/state))
(defn thumbnail-frame-data (defn thumbnail-frame-data
[frame-id] [frame-id]

View file

@ -402,7 +402,7 @@
:style {:-webkit-print-color-adjust :exact} :style {:-webkit-print-color-adjust :exact}
:fill "none"} :fill "none"}
(let [fonts (ff/frame->fonts obj-id objects)] (let [fonts (ff/frame->fonts object-id objects)]
[:& ff/fontfaces-style {:fonts fonts}]) [:& ff/fontfaces-style {:fonts fonts}])
(case (:type object) (case (:type object)

View file

@ -8,7 +8,6 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.geom.shapes.text :as gst]
[app.main.ui.context :as muc] [app.main.ui.context :as muc]
[cuerdas.core :as str] [cuerdas.core :as str]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))

View file

@ -34,9 +34,9 @@
(obj/set! "style" style)))) (obj/set! "style" style))))
(defn translate-shape [attrs shape] (defn translate-shape [attrs shape]
(let [transform (str (usvg/svg-transform-matrix shape) (let [transform (dm/str (usvg/svg-transform-matrix shape)
" " " "
(:transform attrs ""))] (:transform attrs ""))]
(cond-> attrs (cond-> attrs
(and (:svg-viewbox shape) (graphic-element? (-> shape :content :tag))) (and (:svg-viewbox shape) (graphic-element? (-> shape :content :tag)))
(assoc :transform transform)))) (assoc :transform transform))))
@ -60,7 +60,7 @@
(obj/set! "preserveAspectRatio" "none"))] (obj/set! "preserveAspectRatio" "none"))]
[:& (mf/provider svg-ids-ctx) {:value ids-mapping} [:& (mf/provider svg-ids-ctx) {:value ids-mapping}
[:g.svg-raw {:transform (str (gsh/transform-matrix shape))} [:g.svg-raw {:transform (dm/str (gsh/transform-matrix shape))}
[:> "svg" attrs children]]])) [:> "svg" attrs children]]]))
(mf/defc svg-element (mf/defc svg-element

View file

@ -76,15 +76,15 @@
(defn frame->fonts (defn frame->fonts
[frame objects] [frame objects]
(->> (cph/get-children objects (:id frame)) (->> (cph/get-children objects (:id frame))
(filterv cph/text-shape?) (filter cph/text-shape?)
(mapv (comp fonts/get-content-fonts :content)) (map (comp fonts/get-content-fonts :content))
(reduce set/union #{}))) (reduce set/union #{})))
(defn shapes->fonts (defn shapes->fonts
[shapes] [shapes]
(->> shapes (->> shapes
(filterv cph/text-shape?) (filter cph/text-shape?)
(mapv (comp fonts/get-content-fonts :content)) (map (comp fonts/get-content-fonts :content))
(reduce set/union #{}))) (reduce set/union #{})))
(mf/defc fontfaces-style (mf/defc fontfaces-style

View file

@ -7,6 +7,7 @@
(ns app.main.ui.workspace.shapes.frame (ns app.main.ui.workspace.shapes.frame
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.data.macros :as dm]
[app.main.data.workspace.thumbnails :as dwt] [app.main.data.workspace.thumbnails :as dwt]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.ui.hooks :as hooks] [app.main.ui.hooks :as hooks]
@ -35,9 +36,9 @@
childs (mf/deref childs-ref)] childs (mf/deref childs-ref)]
[:& (mf/provider embed/context) {:value true} [:& (mf/provider embed/context) {:value true}
[:> shape-container #js {:shape shape :ref ref} [:& shape-container {:shape shape :ref ref}
[:& ff/fontfaces-style {:fonts fonts}] [:& ff/fontfaces-style {:fonts fonts}]
[:> frame-shape {:shape shape :childs childs} ]]])))) [:& frame-shape {:shape shape :childs childs} ]]]))))
(defn check-props (defn check-props
[new-props old-props] [new-props old-props]
@ -80,7 +81,7 @@
modifiers-ref (mf/use-memo (mf/deps frame-id) #(refs/workspace-modifiers-by-frame-id frame-id)) modifiers-ref (mf/use-memo (mf/deps frame-id) #(refs/workspace-modifiers-by-frame-id frame-id))
modifiers (mf/deref modifiers-ref) modifiers (mf/deref modifiers-ref)
disable-thumbnail? (d/not-empty? (get-in modifiers [(:id shape) :modifiers])) disable-thumbnail? (d/not-empty? (dm/get-in modifiers [(:id shape) :modifiers]))
[on-load-frame-dom thumb-renderer] [on-load-frame-dom thumb-renderer]
(ftr/use-render-thumbnail shape node-ref rendered? thumbnail? disable-thumbnail?) (ftr/use-render-thumbnail shape node-ref rendered? thumbnail? disable-thumbnail?)

View file

@ -68,7 +68,7 @@
#{:app.main.data.workspace.notifications/handle-pointer-update #{:app.main.data.workspace.notifications/handle-pointer-update
:app.main.data.workspace.selection/change-hover-state}) :app.main.data.workspace.selection/change-hover-state})
(defonce ^:dynamic *debug* (atom #{#_:events :thumbnails})) (defonce ^:dynamic *debug* (atom #{#_:events}))
(defn debug-all! [] (reset! *debug* debug-options)) (defn debug-all! [] (reset! *debug* debug-options))
(defn debug-none! [] (reset! *debug* #{})) (defn debug-none! [] (reset! *debug* #{}))