From 3fc9c891acd9357b3cf079915409b3c8367048f1 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 2 Jul 2019 19:07:06 +0200 Subject: [PATCH] fix(frontend): fix many bugs viewer sitemap component --- frontend/src/uxbox/view/ui/viewer.cljs | 36 ++++++++++--------- .../src/uxbox/view/ui/viewer/sitemap.cljs | 28 +++++---------- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/frontend/src/uxbox/view/ui/viewer.cljs b/frontend/src/uxbox/view/ui/viewer.cljs index 6a8a1a49d..132ee95a1 100644 --- a/frontend/src/uxbox/view/ui/viewer.cljs +++ b/frontend/src/uxbox/view/ui/viewer.cljs @@ -18,12 +18,15 @@ ;; --- Refs -(def flags-ref - (-> (l/key :flags) - (l/derive st/state))) +(defn- sort-pages + [{:keys [pages] :as state}] + (let [get-order #(get-in % [:metadata :order])] + (assoc state :pages (->> (sort-by get-order pages) + (into []))))) -(def pages-ref - (-> (l/key :pages) +(def state-ref + (-> (comp (l/select-keys [:flags :pages :project]) + (l/lens sort-pages)) (l/derive st/state))) ;; --- Component @@ -39,7 +42,7 @@ (let [[old-token] (:rum/args oldown) [new-token] (:rum/args own)] (when (not= old-token new-token) - (st/emit! (dv/initialize old-token))) + (st/emit! (dv/initialize new-token))) own)) (mx/defc viewer-page @@ -47,14 +50,13 @@ :will-mount viewer-page-will-mount :did-remount viewer-page-did-remount} [token index id] - (let [flags (mx/react flags-ref) - sitemap? (contains? flags :sitemap) - get-order #(get-in % [:metadata :order]) - pages (mx/react pages-ref)] - [:section.view-content - (when sitemap? - (sitemap pages index)) - (nav flags) - (canvas (if (nil? id) - (nth pages index) - (some #(= id (:id %)) pages)))])) + (let [{:keys [project pages flags]} (mx/react state-ref) + sitemap? (contains? flags :sitemap)] + (when (seq pages) + [:section.view-content + (when sitemap? + (sitemap project pages index)) + (nav flags) + (canvas (if (nil? id) + (nth pages index) + (some #(= id (:id %)) pages)))]))) diff --git a/frontend/src/uxbox/view/ui/viewer/sitemap.cljs b/frontend/src/uxbox/view/ui/viewer/sitemap.cljs index 4c7763d76..474b27eb7 100644 --- a/frontend/src/uxbox/view/ui/viewer/sitemap.cljs +++ b/frontend/src/uxbox/view/ui/viewer/sitemap.cljs @@ -2,31 +2,21 @@ ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; -;; Copyright (c) 2016 Andrey Antukh ;; Copyright (c) 2016 Juan de la Cruz +;; Copyright (c) 2016-2019 Andrey Antukh (ns uxbox.view.ui.viewer.sitemap - (:require [lentes.core :as l] - [potok.core :as ptk] - [uxbox.builtins.icons :as i] - [uxbox.util.i18n :refer [tr]] - [rumext.core :as mx :include-macros true] - [uxbox.util.data :refer [parse-int]] - [uxbox.view.data.viewer :as dv] - [uxbox.view.store :as st])) - -;; --- Refs - -(def project-name-ref - (-> (l/in [:project :name]) - (l/derive st/state))) - -;; --- Component + (:require + [lentes.core :as l] + [rumext.core :as mx :include-macros true] + [uxbox.builtins.icons :as i] + [uxbox.view.data.viewer :as dv] + [uxbox.view.store :as st])) (mx/defc sitemap {:mixins [mx/static mx/reactive]} - [pages selected] - (let [project-name (mx/react project-name-ref) + [project pages selected] + (let [project-name (:name project) on-click #(st/emit! (dv/select-page %))] [:div.view-sitemap [:span.sitemap-title project-name]