Merge pull request #6264 from penpot/elenatorro-10681-update-component-color-preview

🐛 Update the component thumbnail on component change
This commit is contained in:
Elena Torró 2025-04-11 14:33:07 +02:00 committed by GitHub
commit 39c7782019
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,7 @@
[app.common.files.helpers :as cfh]
[app.common.logging :as l]
[app.common.thumbnails :as thc]
[app.common.types.component :as ctc]
[app.common.uuid :as uuid]
[app.main.data.changes :as dch]
[app.main.data.helpers :as dsh]
@ -184,11 +185,11 @@
(rx/filter (ptk/type? ::clear-thumbnail))
(rx/filter #(= (deref %) object-id))))))))))
(defn- extract-root-frame-changes
(defn- extract-frame-changes
"Process a changes set in a commit to extract the frames that are changing"
[page-id [event [old-data new-data]]]
(let [changes (:changes event)
(let [changes (:changes event)
lookup-data-objects
(fn [data page-id]
(dm/get-in data [:pages-index page-id :objects]))
@ -205,21 +206,28 @@
get-frame-ids
(fn get-frame-ids [id]
(let [old-objects (lookup-data-objects old-data page-id)
new-objects (lookup-data-objects new-data page-id)
(let [old-objects (lookup-data-objects old-data page-id)
new-objects (lookup-data-objects new-data page-id)
new-shape (get new-objects id)
old-shape (get old-objects id)
new-shape (get new-objects id)
old-shape (get old-objects id)
old-frame-id (if (cfh/frame-shape? old-shape) id (:frame-id old-shape))
new-frame-id (if (cfh/frame-shape? new-shape) id (:frame-id new-shape))]
old-frame-id (if (cfh/frame-shape? old-shape) id (:frame-id old-shape))
new-frame-id (if (cfh/frame-shape? new-shape) id (:frame-id new-shape))
root-frame-old? (cfh/root-frame? old-objects old-frame-id)
root-frame-new? (cfh/root-frame? new-objects new-frame-id)
instance-root? (ctc/instance-root? new-shape)]
(cond-> #{}
(cfh/root-frame? old-objects old-frame-id)
(conj old-frame-id)
root-frame-old?
(conj ["frame" old-frame-id])
(cfh/root-frame? new-objects new-frame-id)
(conj new-frame-id)
root-frame-new?
(conj ["frame" new-frame-id])
instance-root?
(conj ["component" id])
(and (uuid? (:frame-id old-shape))
(not= uuid/zero (:frame-id old-shape)))
@ -266,7 +274,7 @@
(rx/map deref)
(rx/observe-on :async)
(rx/with-latest-from workspace-data-s)
(rx/merge-map (partial extract-root-frame-changes page-id))
(rx/merge-map (partial extract-frame-changes page-id))
(rx/tap #(l/trc :hint "inconming change" :origin "all" :frame-id (dm/str %)))
(rx/share))
@ -281,15 +289,15 @@
;; and interrupt any ongoing update-thumbnail process
;; related to current frame-id
(->> all-commits-s
(rx/mapcat (fn [frame-id]
(rx/of (clear-thumbnail file-id page-id frame-id "frame")
(clear-thumbnail file-id page-id frame-id "component")))))
(rx/mapcat (fn [[tag frame-id]]
(rx/of (clear-thumbnail file-id page-id frame-id tag)))))
;; Generate thumbnails in batches, once user becomes
;; inactive for some instant.
(->> all-commits-s
(rx/buffer-until notifier-s)
(rx/mapcat #(into #{} %))
(rx/map #(update-thumbnail file-id page-id % "frame" "watch-state-changes"))))
(rx/map (fn [[tag frame-id]]
(update-thumbnail file-id page-id frame-id tag "watch-state-changes")))))
(rx/take-until stopper-s))))))