mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 10:56:20 +00:00
Merge pull request #4787 from penpot/niwinz-bugfix-8
🐛 Fix thumbnails related issues
This commit is contained in:
commit
f3333336f0
@ -10,7 +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.config :as cf]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.changes :as dch]
|
[app.main.data.changes :as dch]
|
||||||
[app.main.data.persistence :as-alias dps]
|
[app.main.data.persistence :as-alias dps]
|
||||||
[app.main.data.workspace.notifications :as-alias wnt]
|
[app.main.data.workspace.notifications :as-alias wnt]
|
||||||
@ -19,7 +19,6 @@
|
|||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.render :as render]
|
[app.main.render :as render]
|
||||||
[app.main.repo :as rp]
|
[app.main.repo :as rp]
|
||||||
[app.util.http :as http]
|
|
||||||
[app.util.queue :as q]
|
[app.util.queue :as q]
|
||||||
[app.util.time :as tp]
|
[app.util.time :as tp]
|
||||||
[app.util.timers :as tm]
|
[app.util.timers :as tm]
|
||||||
@ -149,34 +148,34 @@
|
|||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(l/dbg :hint "update thumbnail" :requester requester :object-id object-id :tag tag)
|
(l/dbg :hint "update thumbnail" :requester requester :object-id object-id :tag tag)
|
||||||
;; Send the update to the back-end
|
(let [tp (tp/tpoint-ms)]
|
||||||
(->> (request-thumbnail state file-id page-id frame-id tag)
|
;; Send the update to the back-end
|
||||||
(rx/mapcat (fn [blob]
|
(->> (request-thumbnail state file-id page-id frame-id tag)
|
||||||
;; Send the data to backend
|
(rx/mapcat (fn [blob]
|
||||||
(let [params {:file-id file-id
|
(let [uri (wapi/create-uri blob)
|
||||||
:object-id object-id
|
params {:file-id file-id
|
||||||
:media blob
|
:object-id object-id
|
||||||
:tag (or tag "frame")}]
|
:media blob
|
||||||
(rp/cmd! :create-file-object-thumbnail params))))
|
:tag (or tag "frame")}]
|
||||||
|
|
||||||
(rx/mapcat (fn [{:keys [object-id media-id]}]
|
(rx/merge
|
||||||
(let [uri (cf/resolve-media media-id)]
|
(rx/of (assoc-thumbnail object-id uri))
|
||||||
;; We perform this request just for
|
(->> (rp/cmd! :create-file-object-thumbnail params)
|
||||||
;; populate the browser CACHE and avoid
|
(rx/catch rx/empty)
|
||||||
;; unnecesary image flickering
|
(rx/ignore))))))
|
||||||
(->> (http/send! {:uri uri :method :get})
|
|
||||||
(rx/map #(assoc-thumbnail object-id uri))))))
|
|
||||||
|
|
||||||
(rx/catch (fn [cause]
|
(rx/catch (fn [cause]
|
||||||
(.error js/console cause)
|
(.error js/console cause)
|
||||||
(rx/empty)))
|
(rx/empty)))
|
||||||
|
|
||||||
;; We cancel all the stream if user starts editing while
|
(rx/tap #(l/trc :hint "thumbnail updated" :elapsed (dm/str (tp) "ms")))
|
||||||
;; thumbnail is generating
|
|
||||||
(rx/take-until
|
;; We cancel all the stream if user starts editing while
|
||||||
(->> stream
|
;; thumbnail is generating
|
||||||
(rx/filter (ptk/type? ::clear-thumbnail))
|
(rx/take-until
|
||||||
(rx/filter #(= (deref %) object-id)))))))))
|
(->> stream
|
||||||
|
(rx/filter (ptk/type? ::clear-thumbnail))
|
||||||
|
(rx/filter #(= (deref %) object-id))))))))))
|
||||||
|
|
||||||
(defn- extract-root-frame-changes
|
(defn- extract-root-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"
|
||||||
@ -192,8 +191,8 @@
|
|||||||
:mov-objects (->> (:shapes change) (map #(vector page-id %)))
|
:mov-objects (->> (:shapes change) (map #(vector page-id %)))
|
||||||
[]))
|
[]))
|
||||||
|
|
||||||
get-frame-id
|
get-frame-ids
|
||||||
(fn [[_ id]]
|
(fn get-frame-ids [id]
|
||||||
(let [old-objects (wsh/lookup-data-objects old-data page-id)
|
(let [old-objects (wsh/lookup-data-objects old-data page-id)
|
||||||
new-objects (wsh/lookup-data-objects new-data page-id)
|
new-objects (wsh/lookup-data-objects new-data page-id)
|
||||||
|
|
||||||
@ -208,12 +207,21 @@
|
|||||||
(conj old-frame-id)
|
(conj old-frame-id)
|
||||||
|
|
||||||
(cfh/root-frame? new-objects new-frame-id)
|
(cfh/root-frame? new-objects new-frame-id)
|
||||||
(conj new-frame-id))))]
|
(conj new-frame-id)
|
||||||
|
|
||||||
|
(and (uuid? (:frame-id old-shape))
|
||||||
|
(not= uuid/zero (:frame-id old-shape)))
|
||||||
|
(into (get-frame-ids (:frame-id old-shape)))
|
||||||
|
|
||||||
|
(and (uuid? (:frame-id new-shape))
|
||||||
|
(not= uuid/zero (:frame-id new-shape)))
|
||||||
|
(into (get-frame-ids (:frame-id new-shape))))))]
|
||||||
|
|
||||||
(into #{}
|
(into #{}
|
||||||
(comp (mapcat extract-ids)
|
(comp (mapcat extract-ids)
|
||||||
(filter (fn [[page-id']] (= page-id page-id')))
|
(filter (fn [[page-id']] (= page-id page-id')))
|
||||||
(mapcat get-frame-id))
|
(map (fn [[_ id]] id))
|
||||||
|
(mapcat get-frame-ids))
|
||||||
changes)))
|
changes)))
|
||||||
|
|
||||||
(defn watch-state-changes
|
(defn watch-state-changes
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user