Improve workspace initialization process.

This commit is contained in:
Andrey Antukh 2016-04-16 13:44:32 +03:00
parent b148de7fc0
commit 2887b5c0e1
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
2 changed files with 53 additions and 22 deletions

View file

@ -108,13 +108,14 @@
(let [pageid (:id (first pages)) (let [pageid (:id (first pages))
params {:project-uuid projectid params {:project-uuid projectid
:page-uuid pageid}] :page-uuid pageid}]
(r/navigate :workspace/page params)))] (rx/of (r/navigate :workspace/page params))))]
(rx/merge (rx/merge
(rx/of (udp/fetch-pages projectid)) (rx/of #(assoc % :loader true)
(udp/fetch-pages projectid))
(->> (rx/filter udp/pages-fetched? s) (->> (rx/filter udp/pages-fetched? s)
(rx/take 1) (rx/take 1)
(rx/map :pages) (rx/map :pages)
(rx/map navigate)))))) (rx/flat-map navigate))))))
(defrecord GoToPage [projectid pageid] (defrecord GoToPage [projectid pageid]
rs/WatchEvent rs/WatchEvent

View file

@ -17,6 +17,7 @@
[uxbox.data.shapes :as uds] [uxbox.data.shapes :as uds]
[uxbox.data.forms :as udf] [uxbox.data.forms :as udf]
[uxbox.data.lightbox :as udl] [uxbox.data.lightbox :as udl]
[uxbox.data.history :as udh]
[uxbox.util.datetime :as dt] [uxbox.util.datetime :as dt]
[uxbox.util.math :as mth] [uxbox.util.math :as mth]
[uxbox.util.data :refer (index-of)] [uxbox.util.data :refer (index-of)]
@ -36,9 +37,8 @@
(declare initialize-alignment-index) (declare initialize-alignment-index)
(defrecord InitializeWorkspace [project page] (defn- setup-workspace-state
rs/UpdateEvent [state project page]
(-apply-update [_ state]
(if (:workspace state) (if (:workspace state)
(update state :workspace merge (update state :workspace merge
{:project project {:project project
@ -53,13 +53,43 @@
:selected #{} :selected #{}
:drawing nil}))) :drawing nil})))
(defrecord InitializeWorkspace [project page]
rs/UpdateEvent
(-apply-update [_ state]
(let [state (setup-workspace-state state project page)]
(if (get-in state [:pages-by-id page])
state
(assoc state :loader true))))
rs/WatchEvent rs/WatchEvent
(-apply-watch [_ state s] (-apply-watch [_ state s]
(if (get-in state [:pages-by-id page]) (let [page' (get-in state [:pages-by-id page])]
(rx/merge
;; Alignment index initialization
(if page'
(rx/of (initialize-alignment-index page)) (rx/of (initialize-alignment-index page))
(->> (rx/filter udp/pages-fetched? s) (->> (rx/filter udp/pages-fetched? s)
(rx/take 1) (rx/take 1)
(rx/map #(initialize-alignment-index page)))))) (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 (defn initialize
"Initialize the workspace state." "Initialize the workspace state."