mirror of
https://github.com/penpot/penpot.git
synced 2025-04-04 19:11:20 -05:00
Improve workspace initialization process.
This commit is contained in:
parent
b148de7fc0
commit
2887b5c0e1
2 changed files with 53 additions and 22 deletions
|
@ -107,14 +107,15 @@
|
|||
(letfn [(navigate [pages]
|
||||
(let [pageid (:id (first pages))
|
||||
params {:project-uuid projectid
|
||||
:page-uuid pageid}]
|
||||
(r/navigate :workspace/page params)))]
|
||||
:page-uuid pageid}]
|
||||
(rx/of (r/navigate :workspace/page params))))]
|
||||
(rx/merge
|
||||
(rx/of (udp/fetch-pages projectid))
|
||||
(rx/of #(assoc % :loader true)
|
||||
(udp/fetch-pages projectid))
|
||||
(->> (rx/filter udp/pages-fetched? s)
|
||||
(rx/take 1)
|
||||
(rx/map :pages)
|
||||
(rx/map navigate))))))
|
||||
(rx/flat-map navigate))))))
|
||||
|
||||
(defrecord GoToPage [projectid pageid]
|
||||
rs/WatchEvent
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
[uxbox.data.shapes :as uds]
|
||||
[uxbox.data.forms :as udf]
|
||||
[uxbox.data.lightbox :as udl]
|
||||
[uxbox.data.history :as udh]
|
||||
[uxbox.util.datetime :as dt]
|
||||
[uxbox.util.math :as mth]
|
||||
[uxbox.util.data :refer (index-of)]
|
||||
|
@ -36,30 +37,59 @@
|
|||
|
||||
(declare initialize-alignment-index)
|
||||
|
||||
(defn- setup-workspace-state
|
||||
[state project page]
|
||||
(if (:workspace state)
|
||||
(update state :workspace merge
|
||||
{:project project
|
||||
:page page
|
||||
:selected #{}
|
||||
:drawing nil})
|
||||
(assoc state :workspace
|
||||
{:project project
|
||||
:zoom 1
|
||||
:page page
|
||||
:flags #{:layers :element-options}
|
||||
:selected #{}
|
||||
:drawing nil})))
|
||||
|
||||
(defrecord InitializeWorkspace [project page]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(if (:workspace state)
|
||||
(update state :workspace merge
|
||||
{:project project
|
||||
:page page
|
||||
:selected #{}
|
||||
:drawing nil})
|
||||
(assoc state :workspace
|
||||
{:project project
|
||||
:zoom 1
|
||||
:page page
|
||||
:flags #{:layers :element-options}
|
||||
:selected #{}
|
||||
:drawing nil})))
|
||||
(let [state (setup-workspace-state state project page)]
|
||||
(if (get-in state [:pages-by-id page])
|
||||
state
|
||||
(assoc state :loader true))))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(if (get-in state [:pages-by-id page])
|
||||
(rx/of (initialize-alignment-index page))
|
||||
(->> (rx/filter udp/pages-fetched? s)
|
||||
(rx/take 1)
|
||||
(rx/map #(initialize-alignment-index page))))))
|
||||
(let [page' (get-in state [:pages-by-id page])]
|
||||
(rx/merge
|
||||
;; Alignment index initialization
|
||||
(if page'
|
||||
(rx/of (initialize-alignment-index page))
|
||||
(->> (rx/filter udp/pages-fetched? s)
|
||||
(rx/take 1)
|
||||
(rx/map #(initialize-alignment-index page))))
|
||||
|
||||
;; Disable loader if it is enabled
|
||||
(when (:loader state)
|
||||
(if page'
|
||||
(->> (rx/of #(assoc % :loader false))
|
||||
(rx/delay 1000))
|
||||
(->> (rx/filter udp/pages-fetched? s)
|
||||
(rx/take 1)
|
||||
(rx/delay 2000)
|
||||
(rx/map (fn [_] #(assoc % :loader false))))))
|
||||
|
||||
;; Page fetching if does not fetched
|
||||
(when-not page'
|
||||
(rx/of (udp/fetch-pages project)))
|
||||
|
||||
;; Initial history loading
|
||||
(rx/of
|
||||
(udh/fetch-page-history page)
|
||||
(udh/fetch-pinned-page-history page))))))
|
||||
|
||||
(defn initialize
|
||||
"Initialize the workspace state."
|
||||
|
|
Loading…
Add table
Reference in a new issue