mirror of
https://github.com/penpot/penpot.git
synced 2025-05-07 16:35:55 +02:00
✨ Minor improvements on workspace initialization.
This commit is contained in:
parent
c15c277b03
commit
d613d00bca
3 changed files with 30 additions and 45 deletions
|
@ -161,40 +161,40 @@
|
|||
(->> stream
|
||||
(rx/filter (ptk/type? ::dwp/bundle-fetched))
|
||||
(rx/take 1)
|
||||
|
||||
(rx/map deref)
|
||||
(rx/mapcat (fn [bundle]
|
||||
(rx/of (dwn/initialize file-id)
|
||||
(dwp/initialize-file-persistence file-id)
|
||||
(dwc/initialize-indices bundle)))))
|
||||
(rx/mapcat (fn [{:keys [project] :as bundle}]
|
||||
(rx/merge
|
||||
(rx/of (dwn/initialize file-id)
|
||||
(dwp/initialize-file-persistence file-id)
|
||||
(dwc/initialize-indices bundle))
|
||||
|
||||
;; Mark file initialized when indexes are ready
|
||||
(->> stream
|
||||
(rx/filter #(= ::dwc/index-initialized %))
|
||||
(rx/first)
|
||||
(rx/map (fn []
|
||||
(file-initialized project-id file-id))))
|
||||
|
||||
))))
|
||||
(->> stream
|
||||
(rx/filter #(= ::dwc/index-initialized %))
|
||||
(rx/first)
|
||||
(rx/map #(file-initialized bundle)))))))))))
|
||||
|
||||
(defn- file-initialized
|
||||
[project-id file-id]
|
||||
[{:keys [file users project libraries] :as bundle}]
|
||||
(ptk/reify ::file-initialized
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(update state :workspace-file
|
||||
(fn [file]
|
||||
(if (= (:id file) file-id)
|
||||
(assoc file :initialized true)
|
||||
file))))
|
||||
(assoc state
|
||||
:current-team-id (:team-id project)
|
||||
:users (d/index-by :id users)
|
||||
:workspace-undo {}
|
||||
:workspace-project project
|
||||
:workspace-file (assoc file :initialized true)
|
||||
:workspace-data (:data file)
|
||||
:workspace-libraries (d/index-by :id libraries)))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [it state stream]
|
||||
(let [ignore-until (get-in state [:workspace-file :ignore-sync-until])
|
||||
(let [file-id (:id file)
|
||||
ignore-until (:ignore-sync-until file)
|
||||
needs-update? (some #(and (> (:modified-at %) (:synced-at %))
|
||||
(or (not ignore-until)
|
||||
(> (:modified-at %) ignore-until)))
|
||||
(vals (get state :workspace-libraries)))]
|
||||
libraries)]
|
||||
(when needs-update?
|
||||
(rx/of (dwl/notify-sync-file file-id)))))))
|
||||
|
||||
|
|
|
@ -263,29 +263,14 @@
|
|||
(rp/query :team-users {:file-id file-id})
|
||||
(rp/query :project {:id project-id})
|
||||
(rp/query :file-libraries {:file-id file-id}))
|
||||
(rx/first)
|
||||
(rx/map (fn [bundle] (apply bundle-fetched bundle)))))))
|
||||
|
||||
(defn- bundle-fetched
|
||||
[file users project libraries]
|
||||
(ptk/reify ::bundle-fetched
|
||||
IDeref
|
||||
(-deref [_]
|
||||
{:file file
|
||||
:users users
|
||||
:project project
|
||||
:libraries libraries})
|
||||
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(assoc state
|
||||
:users (d/index-by :id users)
|
||||
:workspace-undo {}
|
||||
:workspace-project project
|
||||
:workspace-file file
|
||||
:workspace-data (:data file)
|
||||
:workspace-libraries (d/index-by :id libraries)))))
|
||||
|
||||
(rx/take 1)
|
||||
(rx/map (fn [[file users project libraries]]
|
||||
{:file file
|
||||
:users users
|
||||
:project project
|
||||
:libraries libraries}))
|
||||
(rx/mapcat (fn [{:keys [project] :as bundle}]
|
||||
(rx/of (ptk/data-event ::bundle-fetched bundle))))))))
|
||||
|
||||
;; --- Set File shared
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@
|
|||
(mf/use-effect
|
||||
(fn []
|
||||
;; Close any non-modal dialog that may be still open
|
||||
(st/emitf dm/hide)))
|
||||
(st/emit! dm/hide)))
|
||||
|
||||
(mf/use-effect
|
||||
(mf/deps file)
|
||||
|
|
Loading…
Add table
Reference in a new issue