mirror of
https://github.com/penpot/penpot.git
synced 2025-06-02 00:41:42 +02:00
✨ Load workspace thumbnails in a separated request
This commit is contained in:
parent
dfb73192b8
commit
b20d2badfe
11 changed files with 83 additions and 66 deletions
|
@ -132,7 +132,8 @@
|
|||
(->> (rx/of bundle)
|
||||
(rx/mapcat
|
||||
(fn [bundle]
|
||||
(let [bundle (assoc bundle :file (t/decode-str (:file-raw bundle)))
|
||||
(let [file (-> bundle :file-raw t/decode-str)
|
||||
bundle (assoc bundle :file file)
|
||||
team-id (dm/get-in bundle [:project :team-id])]
|
||||
(rx/merge
|
||||
(rx/of (dwn/initialize team-id file-id)
|
||||
|
@ -148,7 +149,7 @@
|
|||
(unchecked-set ug/global "name" name)))))
|
||||
|
||||
(defn- file-initialized
|
||||
[{:keys [file users project libraries file-comments-users] :as bundle}]
|
||||
[{:keys [file thumbnails users project libraries file-comments-users] :as bundle}]
|
||||
(ptk/reify ::file-initialized
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -158,6 +159,7 @@
|
|||
:workspace-undo {}
|
||||
:workspace-project project
|
||||
:workspace-file (assoc file :initialized true)
|
||||
:workspace-thumbnails thumbnails
|
||||
:workspace-data (-> (:data file)
|
||||
(ctst/start-object-indices)
|
||||
;; DEBUG: Uncomment this to try out migrations in local without changing
|
||||
|
|
|
@ -292,13 +292,15 @@
|
|||
(features/active-feature? state :components-v2)
|
||||
(conj "components/v2"))]
|
||||
(->> (rx/zip (rp/cmd! :get-raw-file {:id file-id :features features})
|
||||
(rp/cmd! :get-file-object-thumbnails {:file-id file-id})
|
||||
(rp/query! :team-users {:file-id file-id})
|
||||
(rp/query! :project {:id project-id})
|
||||
(rp/cmd! :get-file-libraries {:file-id file-id})
|
||||
(rp/cmd! :get-profiles-for-file-comments {:file-id file-id :share-id share-id}))
|
||||
(rx/take 1)
|
||||
(rx/map (fn [[file-raw users project libraries file-comments-users]]
|
||||
(rx/map (fn [[file-raw thumbnails users project libraries file-comments-users]]
|
||||
{:file-raw file-raw
|
||||
:thumbnails thumbnails
|
||||
:users users
|
||||
:project project
|
||||
:libraries libraries
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [object-id (dm/str page-id frame-id)]
|
||||
(assoc-in state [:workspace-file :thumbnails object-id] nil)))))
|
||||
(update state :workspace-thumbnails dissoc object-id)))))
|
||||
|
||||
(defn update-thumbnail
|
||||
"Updates the thumbnail information for the given frame `id`"
|
||||
|
@ -63,8 +63,8 @@
|
|||
(ptk/reify ::update-thumbnail
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [object-id (dm/str page-id frame-id)
|
||||
file-id (or file-id (:current-file-id state))
|
||||
(let [object-id (dm/str page-id frame-id)
|
||||
file-id (or file-id (:current-file-id state))
|
||||
blob-result (thumbnail-stream object-id)]
|
||||
|
||||
(->> blob-result
|
||||
|
@ -80,7 +80,7 @@
|
|||
(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))
|
||||
(rx/of #(update % :workspace-thumbnails assoc object-id data))
|
||||
(->> (rp/cmd! :upsert-file-object-thumbnail params)
|
||||
(rx/ignore))))
|
||||
|
||||
|
@ -169,6 +169,6 @@
|
|||
(ptk/reify ::duplicate-thumbnail
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [page-id (get state :current-page-id)
|
||||
old-shape-thumbnail (get-in state [:workspace-file :thumbnails (dm/str page-id old-id)])]
|
||||
(-> state (assoc-in [:workspace-file :thumbnails (dm/str page-id new-id)] old-shape-thumbnail))))))
|
||||
(let [page-id (:current-page-id state)
|
||||
thumbnail (dm/get-in state [:workspace-thumbnails (dm/str page-id old-id)])]
|
||||
(update state :workspace-thumbnails assoc (dm/str page-id new-id) thumbnail)))))
|
||||
|
|
|
@ -408,7 +408,7 @@
|
|||
st/state))
|
||||
|
||||
(def thumbnail-data
|
||||
(l/derived #(dm/get-in % [:workspace-file :thumbnails] {}) st/state))
|
||||
(l/derived #(get % :workspace-thumbnails {}) st/state))
|
||||
|
||||
(defn thumbnail-frame-data
|
||||
[page-id frame-id]
|
||||
|
@ -434,7 +434,7 @@
|
|||
(defn get-flex-child-viewer?
|
||||
[ids page-id]
|
||||
(l/derived
|
||||
(fn [state]
|
||||
(fn [state]
|
||||
(let [objects (wsh/lookup-viewer-objects state page-id)]
|
||||
(filterv #(= :flex (:layout (cph/get-parent objects %))) ids)))
|
||||
st/state =))
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
[beicon.core :as rx]))
|
||||
|
||||
(derive :get-file ::query)
|
||||
(derive :get-file-object-thumbnails ::query)
|
||||
(derive :get-file-libraries ::query)
|
||||
|
||||
(defn handle-response
|
||||
[{:keys [status body] :as response}]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue