0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-02 18:11:20 -05:00

Properly select the first page on workspace first load after dashboard.

This commit is contained in:
Andrey Antukh 2017-01-31 00:17:54 +01:00
parent aba35dee61
commit f33fdc58a6
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
2 changed files with 22 additions and 2 deletions

View file

@ -147,6 +147,9 @@
;; --- Pages Fetched
(deftype PagesFetched [pages]
IDeref
(-deref [_] pages)
ptk/UpdateEvent
(update [_ state]
(as-> state $

View file

@ -205,14 +205,31 @@
;; --- Go To & Go To Page
(deftype GoToFirstPage [pages]
ptk/WatchEvent
(watch [_ state stream]
(let [[page & rest] (sort-by #(get-in % [:metadata :order]) pages)
params {:project (:project page)
:page (:id page)}]
(rx/of (rt/navigate :workspace/page params)))))
(defn go-to-first-page
[pages]
(GoToFirstPage. pages))
(defrecord GoTo [project-id]
ptk/WatchEvent
(watch [_ state stream]
(let [page-id (get-in state [:projects project-id :page-id])
params {:project project-id
:page page-id}]
(rx/of (udp/fetch-pages project-id)
(rt/navigate :workspace/page params)))))
(rx/merge
(rx/of (udp/fetch-pages project-id))
(->> stream
(rx/filter udp/pages-fetched?)
(rx/take 1)
(rx/map deref)
(rx/map go-to-first-page))))))
(defrecord GoToPage [project-id page-id]
ptk/WatchEvent