0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-10 09:08:31 -05:00

🐛 Fix problems with thumbnails

This commit is contained in:
alonso.torres 2022-06-15 13:26:50 +02:00
parent 108291337d
commit e0a1da6bca
5 changed files with 68 additions and 67 deletions

View file

@ -190,7 +190,16 @@
(conj (:id shape))))]
(reduce-objects objects (complement frame-shape?) add-frame [])))
(defn get-root-objects
"Get all the objects under the root object"
[objects]
(let [add-shape
(fn [result shape]
(conj result shape))]
(reduce-objects objects (complement frame-shape?) add-shape [])))
(defn get-root-shapes
"Get all shapes that are not frames"
[objects]
(let [add-shape
(fn [result shape]
@ -688,11 +697,11 @@
(defn start-page-index
[objects]
(with-meta objects {::index-frames (get-frames objects)}))
(with-meta objects {::index-frames (get-frames (with-meta objects nil))}))
(defn update-page-index
[objects]
(with-meta objects {::index-frames (get-frames objects)}))
(with-meta objects {::index-frames (get-frames (with-meta objects nil))}))
(defn start-object-indices
[file]

View file

@ -157,7 +157,7 @@
(->> (rx/from frame-updates)
(rx/flat-map (fn [[page-id frames]]
(->> frames (map #(vector page-id %)))))
(rx/map (fn [[page-id frame-id]] (dwt/update-thumbnail page-id frame-id))))
(rx/map (fn [[page-id frame-id]] (dwt/update-thumbnail (:id file) page-id frame-id))))
(->> (rx/of lagged)
(rx/mapcat seq)
(rx/map #(shapes-changes-persisted file-id %)))))))

View file

@ -56,12 +56,15 @@
(defn update-thumbnail
"Updates the thumbnail information for the given frame `id`"
[page-id frame-id]
([page-id frame-id]
(update-thumbnail nil page-id frame-id))
([file-id page-id frame-id]
(ptk/reify ::update-thumbnail
ptk/WatchEvent
(watch [_ state _]
(let [object-id (dm/str page-id frame-id)
file-id (:current-file-id state)
file-id (or file-id (:current-file-id state))
blob-result (thumbnail-stream object-id)]
(->> blob-result
@ -73,13 +76,15 @@
(rx/merge-map
(fn [data]
(when (some? file-id)
(if (some? file-id)
(let [params {:file-id file-id :object-id object-id :data data}]
(rx/merge
;; Update the local copy of the thumbnails so we don't need to request it again
(rx/of #(assoc-in % [:workspace-file :thumbnails object-id] data))
(->> (rp/mutation! :upsert-file-object-thumbnail params)
(rx/ignore))))))))))))
(rx/ignore))))
(rx/empty))))))))))
(defn- extract-frame-changes
"Process a changes set in a commit to extract the frames that are changing"

View file

@ -62,10 +62,10 @@
(defn- calculate-dimensions
[objects]
(let [rect
(->> (cph/get-immediate-children objects)
(->> (cph/get-root-objects objects)
(map #(if (some? (:children-bounds %))
(:children-bounds %)
(:selrect %)))
(gsh/points->selrect (:points %))))
(gsh/join-selrects))]
(-> rect
(update :x mth/finite 0)
@ -82,9 +82,10 @@
(mf/fnc frame-wrapper
[{:keys [shape] :as props}]
(let [childs (mapv #(get objects %) (:shapes shape))
(let [render-thumbnails? (mf/use-ctx muc/render-thumbnails)
childs (mapv #(get objects %) (:shapes shape))
shape (gsh/transform-shape shape)]
(if (some? (:thumbnail shape))
(if (and render-thumbnails? (some? (:thumbnail shape)))
[:& frame/frame-thumbnail {:shape shape :bounds (:children-bounds shape)}]
[:& frame-shape {:shape shape :childs childs}])))))
@ -221,16 +222,12 @@
vbox (format-viewbox dim)
bgcolor (dm/get-in data [:options :background] default-color)
frame-wrapper
(mf/use-memo
(mf/deps objects)
#(frame-wrapper-factory objects))
shape-wrapper
(mf/use-memo
(mf/deps objects)
#(shape-wrapper-factory objects))]
[:& (mf/provider muc/render-thumbnails) {:value thumbnails?}
[:& (mf/provider embed/context) {:value render-embed?}
[:& (mf/provider export/include-metadata-ctx) {:value include-metadata?}
[:svg {:view-box vbox
@ -254,19 +251,8 @@
[:& ff/fontfaces-style {:fonts fonts}])
(for [item shapes]
(let [frame? (= (:type item) :frame)]
(cond
(and frame? thumbnails? (some? (:thumbnail item)))
[:> shape-container {:shape item}
[:& frame/frame-thumbnail {:shape item :bounds (:children-bounds item)}]]
frame?
[:> shape-container {:shape item}
[:& frame-wrapper {:shape item
:key (:id item)}]]
:else
[:& shape-wrapper {:shape item
:key (:id item)}])))]]]))
:key (:id item)}])]]]]))
;; Component that serves for render frame thumbnails, mainly used in
@ -278,7 +264,7 @@
(let [frame-id (:id frame)
include-metadata? (mf/use-ctx export/include-metadata-ctx)
bounds (or (:children-bounds frame) (:selrect frame))
bounds (or (:children-bounds frame) (gsh/points->rect (:points frame)))
modifier
(mf/with-memo [(:x bounds) (:y bounds)]

View file

@ -23,3 +23,4 @@
(def current-file-id (mf/create-context nil))
(def scroll-ctx (mf/create-context nil))
(def active-frames-ctx (mf/create-context nil))
(def render-thumbnails (mf/create-context nil))