mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 12:59:12 -05:00
✨ Improve thumbnail generation
This commit is contained in:
parent
2ce36ce052
commit
e9064611cf
4 changed files with 25 additions and 27 deletions
|
@ -64,8 +64,12 @@
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [object-id (dm/str page-id frame-id)
|
(let [object-id (dm/str page-id frame-id)
|
||||||
file-id (or file-id (:current-file-id state))
|
file-id (or file-id (:current-file-id state))
|
||||||
blob-result (thumbnail-stream object-id)]
|
blob-result (thumbnail-stream object-id)
|
||||||
|
params {:file-id file-id :object-id object-id :data nil}]
|
||||||
|
|
||||||
|
(rx/concat
|
||||||
|
;; Delete the thumbnail first so if we interrupt we can regenerate after
|
||||||
|
(rp/cmd! :upsert-file-object-thumbnail params)
|
||||||
(->> blob-result
|
(->> blob-result
|
||||||
(rx/merge-map
|
(rx/merge-map
|
||||||
(fn [blob]
|
(fn [blob]
|
||||||
|
@ -76,16 +80,14 @@
|
||||||
(rx/merge-map
|
(rx/merge-map
|
||||||
(fn [data]
|
(fn [data]
|
||||||
(if (some? file-id)
|
(if (some? file-id)
|
||||||
(let [params {:file-id file-id :object-id object-id :data data}]
|
(let [params (assoc params :data data)]
|
||||||
(rx/merge
|
(rx/merge
|
||||||
;; Update the local copy of the thumbnails so we don't need to request it again
|
;; Update the local copy of the thumbnails so we don't need to request it again
|
||||||
(if (some? data)
|
|
||||||
(rx/of #(update % :workspace-thumbnails assoc object-id data))
|
(rx/of #(update % :workspace-thumbnails assoc object-id data))
|
||||||
(rx/empty))
|
|
||||||
(->> (rp/cmd! :upsert-file-object-thumbnail params)
|
(->> (rp/cmd! :upsert-file-object-thumbnail params)
|
||||||
(rx/ignore))))
|
(rx/ignore))))
|
||||||
|
|
||||||
(rx/empty))))))))))
|
(rx/empty)))))))))))
|
||||||
|
|
||||||
(defn- extract-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"
|
||||||
|
|
|
@ -232,7 +232,7 @@
|
||||||
(dom/remove-attribute! (dom/get-parent shape-node) "display")))
|
(dom/remove-attribute! (dom/get-parent shape-node) "display")))
|
||||||
|
|
||||||
(doseq [{:keys [frame shape]} add-children]
|
(doseq [{:keys [frame shape]} add-children]
|
||||||
(let [frame-node (get-shape-node node frame)
|
(let [frame-node (get-shape-node frame)
|
||||||
shape-node (get-shape-node shape)
|
shape-node (get-shape-node shape)
|
||||||
|
|
||||||
use-node
|
use-node
|
||||||
|
|
|
@ -149,6 +149,7 @@
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(fn []
|
(fn []
|
||||||
(when (not @disable-ref?)
|
(when (not @disable-ref?)
|
||||||
|
(reset! render-frame? true)
|
||||||
(reset! regenerate-thumbnail true))))
|
(reset! regenerate-thumbnail true))))
|
||||||
|
|
||||||
on-load-frame-dom
|
on-load-frame-dom
|
||||||
|
@ -168,12 +169,6 @@
|
||||||
(when (and (some? prev-thumbnail-data) (nil? thumbnail-data))
|
(when (and (some? prev-thumbnail-data) (nil? thumbnail-data))
|
||||||
(rx/push! updates-str :update))))
|
(rx/push! updates-str :update))))
|
||||||
|
|
||||||
(mf/use-effect
|
|
||||||
(mf/deps @render-frame? thumbnail-data)
|
|
||||||
(fn []
|
|
||||||
(when (and (some? thumbnail-data) @render-frame?)
|
|
||||||
(reset! render-frame? false))))
|
|
||||||
|
|
||||||
(mf/use-effect
|
(mf/use-effect
|
||||||
(mf/deps force-render)
|
(mf/deps force-render)
|
||||||
(fn []
|
(fn []
|
||||||
|
|
|
@ -278,8 +278,9 @@
|
||||||
(> zoom 1.3)
|
(> zoom 1.3)
|
||||||
|
|
||||||
;; Zoom >= 25% will show frames hovering
|
;; Zoom >= 25% will show frames hovering
|
||||||
|
;; Also, if we're moving a shape over the frame we need to remove the thumbnail
|
||||||
(and
|
(and
|
||||||
(>= zoom 0.25)
|
(or (= :move transform) (>= zoom 0.25))
|
||||||
(or (contains? hover-ids? id) (contains? @last-hover-ids id)))
|
(or (contains? hover-ids? id) (contains? @last-hover-ids id)))
|
||||||
|
|
||||||
;; Otherwise, if it's a selected frame
|
;; Otherwise, if it's a selected frame
|
||||||
|
|
Loading…
Add table
Reference in a new issue