From f33fdc58a6f693cd726217d7cba3efd2b78a0a28 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 31 Jan 2017 00:17:54 +0100 Subject: [PATCH] Properly select the first page on workspace first load after dashboard. --- frontend/src/uxbox/main/data/pages.cljs | 3 +++ frontend/src/uxbox/main/data/projects.cljs | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/frontend/src/uxbox/main/data/pages.cljs b/frontend/src/uxbox/main/data/pages.cljs index f719b7905..fa99a566c 100644 --- a/frontend/src/uxbox/main/data/pages.cljs +++ b/frontend/src/uxbox/main/data/pages.cljs @@ -147,6 +147,9 @@ ;; --- Pages Fetched (deftype PagesFetched [pages] + IDeref + (-deref [_] pages) + ptk/UpdateEvent (update [_ state] (as-> state $ diff --git a/frontend/src/uxbox/main/data/projects.cljs b/frontend/src/uxbox/main/data/projects.cljs index a7d663476..974e70a90 100644 --- a/frontend/src/uxbox/main/data/projects.cljs +++ b/frontend/src/uxbox/main/data/projects.cljs @@ -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