mirror of
https://github.com/penpot/penpot.git
synced 2025-04-30 07:26:20 +02:00
Merge pull request #6264 from penpot/elenatorro-10681-update-component-color-preview
🐛 Update the component thumbnail on component change
This commit is contained in:
commit
39c7782019
1 changed files with 25 additions and 17 deletions
|
@ -10,6 +10,7 @@
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.common.thumbnails :as thc]
|
[app.common.thumbnails :as thc]
|
||||||
|
[app.common.types.component :as ctc]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.changes :as dch]
|
[app.main.data.changes :as dch]
|
||||||
[app.main.data.helpers :as dsh]
|
[app.main.data.helpers :as dsh]
|
||||||
|
@ -184,11 +185,11 @@
|
||||||
(rx/filter (ptk/type? ::clear-thumbnail))
|
(rx/filter (ptk/type? ::clear-thumbnail))
|
||||||
(rx/filter #(= (deref %) object-id))))))))))
|
(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"
|
"Process a changes set in a commit to extract the frames that are changing"
|
||||||
[page-id [event [old-data new-data]]]
|
[page-id [event [old-data new-data]]]
|
||||||
(let [changes (:changes event)
|
|
||||||
|
|
||||||
|
(let [changes (:changes event)
|
||||||
lookup-data-objects
|
lookup-data-objects
|
||||||
(fn [data page-id]
|
(fn [data page-id]
|
||||||
(dm/get-in data [:pages-index page-id :objects]))
|
(dm/get-in data [:pages-index page-id :objects]))
|
||||||
|
@ -212,14 +213,21 @@
|
||||||
old-shape (get old-objects id)
|
old-shape (get old-objects id)
|
||||||
|
|
||||||
old-frame-id (if (cfh/frame-shape? old-shape) id (:frame-id old-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))]
|
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-> #{}
|
(cond-> #{}
|
||||||
(cfh/root-frame? old-objects old-frame-id)
|
root-frame-old?
|
||||||
(conj old-frame-id)
|
(conj ["frame" old-frame-id])
|
||||||
|
|
||||||
(cfh/root-frame? new-objects new-frame-id)
|
root-frame-new?
|
||||||
(conj new-frame-id)
|
(conj ["frame" new-frame-id])
|
||||||
|
|
||||||
|
instance-root?
|
||||||
|
(conj ["component" id])
|
||||||
|
|
||||||
(and (uuid? (:frame-id old-shape))
|
(and (uuid? (:frame-id old-shape))
|
||||||
(not= uuid/zero (:frame-id old-shape)))
|
(not= uuid/zero (:frame-id old-shape)))
|
||||||
|
@ -266,7 +274,7 @@
|
||||||
(rx/map deref)
|
(rx/map deref)
|
||||||
(rx/observe-on :async)
|
(rx/observe-on :async)
|
||||||
(rx/with-latest-from workspace-data-s)
|
(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/tap #(l/trc :hint "inconming change" :origin "all" :frame-id (dm/str %)))
|
||||||
(rx/share))
|
(rx/share))
|
||||||
|
|
||||||
|
@ -281,15 +289,15 @@
|
||||||
;; and interrupt any ongoing update-thumbnail process
|
;; and interrupt any ongoing update-thumbnail process
|
||||||
;; related to current frame-id
|
;; related to current frame-id
|
||||||
(->> all-commits-s
|
(->> all-commits-s
|
||||||
(rx/mapcat (fn [frame-id]
|
(rx/mapcat (fn [[tag frame-id]]
|
||||||
(rx/of (clear-thumbnail file-id page-id frame-id "frame")
|
(rx/of (clear-thumbnail file-id page-id frame-id tag)))))
|
||||||
(clear-thumbnail file-id page-id frame-id "component")))))
|
|
||||||
|
|
||||||
;; Generate thumbnails in batches, once user becomes
|
;; Generate thumbnails in batches, once user becomes
|
||||||
;; inactive for some instant.
|
;; inactive for some instant.
|
||||||
(->> all-commits-s
|
(->> all-commits-s
|
||||||
(rx/buffer-until notifier-s)
|
(rx/buffer-until notifier-s)
|
||||||
(rx/mapcat #(into #{} %))
|
(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))))))
|
(rx/take-until stopper-s))))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue