0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 07:50:43 -05:00

fix(frontend): fix many bugs viewer sitemap component

This commit is contained in:
Andrey Antukh 2019-07-02 19:07:06 +02:00
parent 095989e6ba
commit 3fc9c891ac
2 changed files with 28 additions and 36 deletions

View file

@ -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)))])))

View file

@ -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 <niwi@niwi.nz>
;; Copyright (c) 2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
;; Copyright (c) 2016-2019 Andrey Antukh <niwi@niwi.nz>
(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]