mirror of
https://github.com/penpot/penpot.git
synced 2025-01-27 00:49:28 -05:00
Improved projects, colors and workspace page data loading.
This commit is contained in:
parent
191fae23d3
commit
efad3ff73c
6 changed files with 117 additions and 81 deletions
|
@ -9,10 +9,38 @@
|
||||||
(:require [clojure.set :as set]
|
(:require [clojure.set :as set]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[uuid.core :as uuid]
|
[uuid.core :as uuid]
|
||||||
|
[uxbox.state :as st]
|
||||||
[uxbox.rstore :as rs]
|
[uxbox.rstore :as rs]
|
||||||
[uxbox.state.colors :as stc]
|
[uxbox.state.colors :as stc]
|
||||||
[uxbox.repo :as rp]))
|
[uxbox.repo :as rp]))
|
||||||
|
|
||||||
|
;; --- Initialize
|
||||||
|
|
||||||
|
(declare fetch-collections)
|
||||||
|
(declare collections-fetched?)
|
||||||
|
|
||||||
|
(defrecord Initialize []
|
||||||
|
rs/EffectEvent
|
||||||
|
(-apply-effect [_ state]
|
||||||
|
(when-not (seq (:colors-by-id state))
|
||||||
|
(reset! st/loader true)))
|
||||||
|
|
||||||
|
rs/WatchEvent
|
||||||
|
(-apply-watch [_ state s]
|
||||||
|
(let [colors (seq (:colors-by-id state))]
|
||||||
|
(if colors
|
||||||
|
(rx/empty)
|
||||||
|
(rx/merge
|
||||||
|
(rx/of (fetch-collections))
|
||||||
|
(->> (rx/filter collections-fetched? s)
|
||||||
|
(rx/take 1)
|
||||||
|
(rx/do #(reset! st/loader false))
|
||||||
|
(rx/ignore)))))))
|
||||||
|
|
||||||
|
(defn initialize
|
||||||
|
[]
|
||||||
|
(Initialize.))
|
||||||
|
|
||||||
;; --- Collections Fetched
|
;; --- Collections Fetched
|
||||||
|
|
||||||
(defrecord CollectionFetched [items]
|
(defrecord CollectionFetched [items]
|
||||||
|
@ -24,6 +52,10 @@
|
||||||
[items]
|
[items]
|
||||||
(CollectionFetched. items))
|
(CollectionFetched. items))
|
||||||
|
|
||||||
|
(defn collections-fetched?
|
||||||
|
[v]
|
||||||
|
(instance? CollectionFetched v))
|
||||||
|
|
||||||
;; --- Fetch Collections
|
;; --- Fetch Collections
|
||||||
|
|
||||||
(defrecord FetchCollections []
|
(defrecord FetchCollections []
|
||||||
|
|
|
@ -19,40 +19,13 @@
|
||||||
|
|
||||||
;; --- Events
|
;; --- Events
|
||||||
|
|
||||||
(defn- setup-dashboard-state
|
|
||||||
[state section]
|
|
||||||
(update state :dashboard assoc
|
|
||||||
:section section
|
|
||||||
:collection-type :builtin
|
|
||||||
:collection-id 1))
|
|
||||||
|
|
||||||
(defrecord InitializeDashboard [section]
|
(defrecord InitializeDashboard [section]
|
||||||
rs/UpdateEvent
|
rs/UpdateEvent
|
||||||
(-apply-update [_ state]
|
(-apply-update [_ state]
|
||||||
(let [state (setup-dashboard-state state section)]
|
(update state :dashboard assoc
|
||||||
(if (seq (:projects-by-id state))
|
:section section
|
||||||
state
|
:collection-type :builtin
|
||||||
(assoc state :loader true))))
|
:collection-id 1)))
|
||||||
|
|
||||||
rs/WatchEvent
|
|
||||||
(-apply-watch [_ state s]
|
|
||||||
(let [projects (seq (:projects-by-id state))
|
|
||||||
color-collections (seq (:colors-by-id state))]
|
|
||||||
(rx/merge
|
|
||||||
;; Load projects if needed
|
|
||||||
(if projects
|
|
||||||
(rx/empty)
|
|
||||||
(rx/of (dp/fetch-projects)))
|
|
||||||
|
|
||||||
(rx/of (dc/fetch-collections))
|
|
||||||
|
|
||||||
(when (:loader state)
|
|
||||||
(if projects
|
|
||||||
(rx/of #(assoc % :loader false))
|
|
||||||
(->> (rx/filter dp/projects-fetched? s)
|
|
||||||
(rx/take 1)
|
|
||||||
(rx/delay 1000)
|
|
||||||
(rx/map (fn [_] #(assoc % :loader false))))))))))
|
|
||||||
|
|
||||||
(defn initialize
|
(defn initialize
|
||||||
[section]
|
[section]
|
||||||
|
|
|
@ -10,12 +10,40 @@
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[uxbox.rstore :as rs]
|
[uxbox.rstore :as rs]
|
||||||
[uxbox.router :as r]
|
[uxbox.router :as r]
|
||||||
|
[uxbox.state :as st]
|
||||||
[uxbox.repo :as rp]
|
[uxbox.repo :as rp]
|
||||||
[uxbox.locales :refer (tr)]
|
[uxbox.locales :refer (tr)]
|
||||||
[uxbox.schema :as sc]
|
[uxbox.schema :as sc]
|
||||||
[uxbox.state.project :as stpr]
|
[uxbox.state.project :as stpr]
|
||||||
[uxbox.data.pages :as udp]))
|
[uxbox.data.pages :as udp]))
|
||||||
|
|
||||||
|
;; --- Initialize
|
||||||
|
|
||||||
|
(declare fetch-projects)
|
||||||
|
(declare projects-fetched?)
|
||||||
|
|
||||||
|
(defrecord Initialize []
|
||||||
|
rs/EffectEvent
|
||||||
|
(-apply-effect [_ state]
|
||||||
|
(when-not (seq (:projects-by-id state))
|
||||||
|
(reset! st/loader true)))
|
||||||
|
|
||||||
|
rs/WatchEvent
|
||||||
|
(-apply-watch [_ state s]
|
||||||
|
(let [projects (seq (:projects-by-id state))]
|
||||||
|
(if projects
|
||||||
|
(rx/empty)
|
||||||
|
(rx/merge
|
||||||
|
(rx/of (fetch-projects))
|
||||||
|
(->> (rx/filter projects-fetched? s)
|
||||||
|
(rx/take 1)
|
||||||
|
(rx/do #(reset! st/loader false))
|
||||||
|
(rx/ignore)))))))
|
||||||
|
|
||||||
|
(defn initialize
|
||||||
|
[]
|
||||||
|
(Initialize.))
|
||||||
|
|
||||||
;; --- Projects Fetched
|
;; --- Projects Fetched
|
||||||
|
|
||||||
(defrecord ProjectsFetched [projects]
|
(defrecord ProjectsFetched [projects]
|
||||||
|
@ -102,20 +130,25 @@
|
||||||
;; --- Go To & Go To Page
|
;; --- Go To & Go To Page
|
||||||
|
|
||||||
(defrecord GoTo [projectid]
|
(defrecord GoTo [projectid]
|
||||||
|
rs/EffectEvent
|
||||||
|
(-apply-effect [_ state]
|
||||||
|
(reset! st/loader true))
|
||||||
|
|
||||||
rs/WatchEvent
|
rs/WatchEvent
|
||||||
(-apply-watch [_ state s]
|
(-apply-watch [_ state s]
|
||||||
(letfn [(navigate [pages]
|
(letfn [(navigate [pages]
|
||||||
(let [pageid (:id (first pages))
|
(let [pageid (:id (first pages))
|
||||||
params {:project-uuid projectid
|
params {:project-uuid projectid
|
||||||
:page-uuid pageid}]
|
:page-uuid pageid}]
|
||||||
(rx/of (r/navigate :workspace/page params))))]
|
(r/navigate :workspace/page params)))]
|
||||||
(rx/merge
|
(rx/merge
|
||||||
(rx/of #(assoc % :loader true)
|
(rx/of #(assoc % :loader true)
|
||||||
(udp/fetch-pages projectid))
|
(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/flat-map navigate))))))
|
(rx/do #(reset! st/loader false))
|
||||||
|
(rx/map navigate))))))
|
||||||
|
|
||||||
(defrecord GoToPage [projectid pageid]
|
(defrecord GoToPage [projectid pageid]
|
||||||
rs/WatchEvent
|
rs/WatchEvent
|
||||||
|
|
|
@ -10,9 +10,11 @@
|
||||||
[uuid.core :as uuid]
|
[uuid.core :as uuid]
|
||||||
[uxbox.constants :as c]
|
[uxbox.constants :as c]
|
||||||
[uxbox.rstore :as rs]
|
[uxbox.rstore :as rs]
|
||||||
|
[uxbox.state :as st]
|
||||||
[uxbox.state.shapes :as stsh]
|
[uxbox.state.shapes :as stsh]
|
||||||
[uxbox.schema :as sc]
|
[uxbox.schema :as sc]
|
||||||
[uxbox.data.core :refer (worker)]
|
[uxbox.data.core :refer (worker)]
|
||||||
|
[uxbox.data.projects :as dp]
|
||||||
[uxbox.data.pages :as udp]
|
[uxbox.data.pages :as udp]
|
||||||
[uxbox.data.shapes :as uds]
|
[uxbox.data.shapes :as uds]
|
||||||
[uxbox.data.forms :as udf]
|
[uxbox.data.forms :as udf]
|
||||||
|
@ -37,8 +39,9 @@
|
||||||
|
|
||||||
(declare initialize-alignment-index)
|
(declare initialize-alignment-index)
|
||||||
|
|
||||||
(defn- setup-workspace-state
|
(defrecord InitializeWorkspace [project page]
|
||||||
[state project page]
|
rs/UpdateEvent
|
||||||
|
(-apply-update [_ state]
|
||||||
(if (:workspace state)
|
(if (:workspace state)
|
||||||
(update state :workspace merge
|
(update state :workspace merge
|
||||||
{:project project
|
{:project project
|
||||||
|
@ -53,49 +56,42 @@
|
||||||
: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]
|
||||||
(let [page' (get-in state [:pages-by-id page])]
|
(let [page-id page
|
||||||
|
page (get-in state [:pages-by-id page-id])]
|
||||||
|
|
||||||
|
;; Activate loaded if page is not fetched.
|
||||||
|
(when-not page (reset! st/loader true))
|
||||||
|
|
||||||
(rx/merge
|
(rx/merge
|
||||||
;; Alignment index initialization
|
(if page
|
||||||
(if page'
|
(rx/of (initialize-alignment-index page-id))
|
||||||
(rx/of (initialize-alignment-index page))
|
(rx/merge
|
||||||
|
(rx/of (udp/fetch-pages project))
|
||||||
(->> (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/do #(reset! st/loader false))
|
||||||
|
(rx/map #(initialize-alignment-index page-id)))))
|
||||||
;; 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
|
;; Initial history loading
|
||||||
(rx/of
|
(rx/of
|
||||||
(udh/fetch-page-history page)
|
(udh/fetch-page-history page-id)
|
||||||
(udh/fetch-pinned-page-history page))))))
|
(udh/fetch-pinned-page-history page-id)))))
|
||||||
|
|
||||||
|
rs/EffectEvent
|
||||||
|
(-apply-effect [_ state]
|
||||||
|
;; Optimistic prefetch of projects if them are not already fetched
|
||||||
|
(when-not (seq (:projects-by-id state))
|
||||||
|
(rs/emit! (dp/fetch-projects)))))
|
||||||
|
|
||||||
(defn initialize
|
(defn initialize
|
||||||
"Initialize the workspace state."
|
"Initialize the workspace state."
|
||||||
[project page]
|
[project page]
|
||||||
(InitializeWorkspace. project page))
|
(InitializeWorkspace. project page))
|
||||||
|
|
||||||
|
;; --- Toggle Flag
|
||||||
|
|
||||||
(defn toggle-flag
|
(defn toggle-flag
|
||||||
"Toggle the enabled flag of the specified tool."
|
"Toggle the enabled flag of the specified tool."
|
||||||
[key]
|
[key]
|
||||||
|
|
|
@ -231,7 +231,8 @@
|
||||||
|
|
||||||
(defn colors-page-will-mount
|
(defn colors-page-will-mount
|
||||||
[own]
|
[own]
|
||||||
(rs/emit! (dd/initialize :dashboard/colors))
|
(rs/emit! (dd/initialize :dashboard/colors)
|
||||||
|
(dc/initialize))
|
||||||
own)
|
own)
|
||||||
|
|
||||||
(defn colors-page-transfer-state
|
(defn colors-page-transfer-state
|
||||||
|
|
|
@ -230,7 +230,8 @@
|
||||||
|
|
||||||
(defn projects-page-will-mount
|
(defn projects-page-will-mount
|
||||||
[own]
|
[own]
|
||||||
(rs/emit! (dd/initialize :dashboard/projects))
|
(rs/emit! (dd/initialize :dashboard/projects)
|
||||||
|
(dp/initialize))
|
||||||
own)
|
own)
|
||||||
|
|
||||||
(defn projects-page-transfer-state
|
(defn projects-page-transfer-state
|
||||||
|
|
Loading…
Add table
Reference in a new issue