mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 23:49:45 -05:00
✨ Improve pages fetching on dashboard.
This commit is contained in:
parent
426677935e
commit
761a3c102f
4 changed files with 14 additions and 14 deletions
|
@ -59,8 +59,8 @@
|
|||
;; --- Pages creation
|
||||
|
||||
(def create-page-sql
|
||||
"insert into pages (id, user_id, project_id, name, data, metadata)
|
||||
values ($1, $2, $3, $4, $5, $6)
|
||||
"insert into pages (id, user_id, project_id, name, ordering, data, metadata)
|
||||
values ($1, $2, $3, $4, $5, $6, $7)
|
||||
returning *;")
|
||||
|
||||
(defn create-page
|
||||
|
@ -79,6 +79,7 @@
|
|||
(mk-uuid "user" uid)
|
||||
(mk-uuid "project" pjid uid)
|
||||
(str "page " paid)
|
||||
paid
|
||||
(blob/encode data)
|
||||
(blob/encode {})])))
|
||||
|
||||
|
|
|
@ -36,15 +36,19 @@
|
|||
[{:keys [user] :as params}]
|
||||
(let [sql "select distinct on (p.id, p.created_at)
|
||||
p.*,
|
||||
first_value(pg.id)
|
||||
over (partition by p.id order by pg.created_at)
|
||||
as ref_page_id
|
||||
array_agg(pg.id) over (
|
||||
partition by p.id
|
||||
order by pg.created_at
|
||||
range between unbounded preceding and unbounded following
|
||||
) as pages
|
||||
from projects as p
|
||||
right join pages as pg
|
||||
on (pg.project_id = p.id)
|
||||
where p.user_id = $1
|
||||
order by p.created_at asc"]
|
||||
(db/query db/pool [sql user])))
|
||||
(-> (db/query db/pool [sql user])
|
||||
(p/then (fn [rows]
|
||||
(mapv #(update % :pages vec) rows))))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Mutations
|
||||
|
|
|
@ -75,11 +75,6 @@
|
|||
(update [_ state]
|
||||
(reduce assoc-project state projects))))
|
||||
|
||||
;; ptk/WatchEvent
|
||||
;; (watch [_ state stream]
|
||||
;; (->> (rx/from-coll (map :id projects))
|
||||
;; (rx/map udp/fetch-pages))))
|
||||
|
||||
(defn projects-fetched?
|
||||
[v]
|
||||
(= ::projects-fetched (ptk/type v)))
|
||||
|
@ -177,8 +172,8 @@
|
|||
(ptk/reify ::go-to
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page-id (get-in state [:projects id :ref-page-id])]
|
||||
(let [params {:project id :page page-id}]
|
||||
(let [page-ids (get-in state [:projects id :pages])]
|
||||
(let [params {:project id :page (first page-ids)}]
|
||||
(rx/of (rt/nav :workspace/page params)))))))
|
||||
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
;; Activate loaded if page is not fetched.
|
||||
(when-not page (reset! st/loader true))
|
||||
(rx/merge
|
||||
;; TODO: the `fetch-pages` should fetch a limited set of attrs
|
||||
;; TODO: the `fetch-pages` should fetch a limited set of attrs?
|
||||
(rx/of (udp/fetch-page page-id))
|
||||
(rx/of (udp/fetch-pages project-id))
|
||||
(->> stream
|
||||
|
|
Loading…
Add table
Reference in a new issue