mirror of
https://github.com/penpot/penpot.git
synced 2025-05-08 20:05:54 +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
|
(->> stream
|
||||||
(rx/filter (ptk/type? ::dwp/bundle-fetched))
|
(rx/filter (ptk/type? ::dwp/bundle-fetched))
|
||||||
(rx/take 1)
|
(rx/take 1)
|
||||||
|
|
||||||
(rx/map deref)
|
(rx/map deref)
|
||||||
(rx/mapcat (fn [bundle]
|
(rx/mapcat (fn [{:keys [project] :as bundle}]
|
||||||
|
(rx/merge
|
||||||
(rx/of (dwn/initialize file-id)
|
(rx/of (dwn/initialize file-id)
|
||||||
(dwp/initialize-file-persistence file-id)
|
(dwp/initialize-file-persistence file-id)
|
||||||
(dwc/initialize-indices bundle)))))
|
(dwc/initialize-indices bundle))
|
||||||
|
|
||||||
;; Mark file initialized when indexes are ready
|
|
||||||
(->> stream
|
(->> stream
|
||||||
(rx/filter #(= ::dwc/index-initialized %))
|
(rx/filter #(= ::dwc/index-initialized %))
|
||||||
(rx/first)
|
(rx/first)
|
||||||
(rx/map (fn []
|
(rx/map #(file-initialized bundle)))))))))))
|
||||||
(file-initialized project-id file-id))))
|
|
||||||
|
|
||||||
))))
|
|
||||||
|
|
||||||
(defn- file-initialized
|
(defn- file-initialized
|
||||||
[project-id file-id]
|
[{:keys [file users project libraries] :as bundle}]
|
||||||
(ptk/reify ::file-initialized
|
(ptk/reify ::file-initialized
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(update state :workspace-file
|
(assoc state
|
||||||
(fn [file]
|
:current-team-id (:team-id project)
|
||||||
(if (= (:id file) file-id)
|
:users (d/index-by :id users)
|
||||||
(assoc file :initialized true)
|
:workspace-undo {}
|
||||||
file))))
|
:workspace-project project
|
||||||
|
:workspace-file (assoc file :initialized true)
|
||||||
|
:workspace-data (:data file)
|
||||||
|
:workspace-libraries (d/index-by :id libraries)))
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state stream]
|
(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 %))
|
needs-update? (some #(and (> (:modified-at %) (:synced-at %))
|
||||||
(or (not ignore-until)
|
(or (not ignore-until)
|
||||||
(> (:modified-at %) ignore-until)))
|
(> (:modified-at %) ignore-until)))
|
||||||
(vals (get state :workspace-libraries)))]
|
libraries)]
|
||||||
(when needs-update?
|
(when needs-update?
|
||||||
(rx/of (dwl/notify-sync-file file-id)))))))
|
(rx/of (dwl/notify-sync-file file-id)))))))
|
||||||
|
|
||||||
|
|
|
@ -263,29 +263,14 @@
|
||||||
(rp/query :team-users {:file-id file-id})
|
(rp/query :team-users {:file-id file-id})
|
||||||
(rp/query :project {:id project-id})
|
(rp/query :project {:id project-id})
|
||||||
(rp/query :file-libraries {:file-id file-id}))
|
(rp/query :file-libraries {:file-id file-id}))
|
||||||
(rx/first)
|
(rx/take 1)
|
||||||
(rx/map (fn [bundle] (apply bundle-fetched bundle)))))))
|
(rx/map (fn [[file users project libraries]]
|
||||||
|
|
||||||
(defn- bundle-fetched
|
|
||||||
[file users project libraries]
|
|
||||||
(ptk/reify ::bundle-fetched
|
|
||||||
IDeref
|
|
||||||
(-deref [_]
|
|
||||||
{:file file
|
{:file file
|
||||||
:users users
|
:users users
|
||||||
:project project
|
:project project
|
||||||
:libraries libraries})
|
:libraries libraries}))
|
||||||
|
(rx/mapcat (fn [{:keys [project] :as bundle}]
|
||||||
ptk/UpdateEvent
|
(rx/of (ptk/data-event ::bundle-fetched bundle))))))))
|
||||||
(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)))))
|
|
||||||
|
|
||||||
|
|
||||||
;; --- Set File shared
|
;; --- Set File shared
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,7 @@
|
||||||
(mf/use-effect
|
(mf/use-effect
|
||||||
(fn []
|
(fn []
|
||||||
;; Close any non-modal dialog that may be still open
|
;; Close any non-modal dialog that may be still open
|
||||||
(st/emitf dm/hide)))
|
(st/emit! dm/hide)))
|
||||||
|
|
||||||
(mf/use-effect
|
(mf/use-effect
|
||||||
(mf/deps file)
|
(mf/deps file)
|
||||||
|
|
Loading…
Add table
Reference in a new issue