0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00

Add navigation to dashboard.

This commit is contained in:
Andrey Antukh 2015-12-16 13:57:42 +02:00
parent feb00d83f8
commit 61b05613f3
4 changed files with 44 additions and 20 deletions

View file

@ -132,6 +132,17 @@
(-pr-writer [mv writer _]
(-write writer "#<event:u.s.p/initialize-workspace>"))))
(defn set-dashboard-section
[section]
(reify
rs/UpdateEvent
(-apply-update [_ state]
(assoc-in state [:dashboard :section] section))
IPrintWithWriter
(-pr-writer [mv writer _]
(-write writer "#<event:u.s.p/go-to-project"))))
(defn go-to-project
"A shortcut event that redirects the user to the
first page of the project."

View file

@ -57,8 +57,8 @@
(def ^:static
routes ["/" [["auth/login" :auth/login]
["auth/register" :auth/register]
["auth/recover" :auth/recover-password]
;; ["auth/register" :auth/register]
;; ["auth/recover" :auth/recover-password]
["dashboard/" [["projects" :dashboard/projects]
["elements" :dashboard/elements]
["icons" :dashboard/icons]
@ -66,13 +66,10 @@
["workspace/" [[project-route :main/project]
[page-route :main/page]]]]])
(defn- on-navigate
[data]
(rs/emit! (update-location data)))
(defonce +router+
(bidi.router/start-router! routes {:on-navigate on-navigate
:default-location {:handler :auth/login}}))
(let [opts {:on-navigate #(rs/emit! (update-location %))
:default-location {:handler :dashboard/projects}}]
(bidi.router/start-router! routes opts)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Public Api

View file

@ -9,7 +9,7 @@
(defonce stream
(rs/init {:user {:fullname "Cirilla"
:avatar "http://lorempixel.com/50/50/"}
:workspace nil
:dashboard {:section :dashboard/projects}
:projects-by-id {}
:pages-by-id {}}))

View file

@ -1,32 +1,48 @@
(ns uxbox.ui.dashboard.header
(:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum]
[cats.labs.lens :as l]
[uxbox.util :as util]
[uxbox.router :as r]
[uxbox.rstore :as rs]
[uxbox.state :as s]
[uxbox.data.projects :as dp]
[uxbox.ui.navigation :as nav]
[uxbox.ui.icons :as i]
[uxbox.ui.users :as ui.u]))
(def ^:static header-state
(as-> (l/in [:dashboard]) $
(l/focus-atom $ s/state)))
(defn- header-link
[section content]
(let [link (r/route-for section)
on-click #(rs/emit! (dp/set-dashboard-section section))]
(html
[:a {:href (str "/#" link) :on-click on-click} content])))
(defn header-render
[own]
(let [local (:rum/local own)
projects? (= (:section local) :projects)
elements? (= (:section local) :elements)
icons? (= (:section local) :icons)
colors? (= (:section local) :colores)]
(let [local (rum/react header-state)
projects? (= (:section local) :dashboard/projects)
elements? (= (:section local) :dashboard/elements)
icons? (= (:section local) :dashboard/icons)
colors? (= (:section local) :dashboard/colors)]
(html
[:header#main-bar.main-bar
[:div.main-logo
(nav/link "/" i/logo)]
(header-link :dashboard/projects i/logo)]
[:ul.main-nav
[:li {:class (when projects? "current")}
(nav/link (r/route-for :dashboard/projects) "PROJECTS")]
(header-link :dashboard/projects "PROJECTS")]
[:li {:class (when elements? "current")}
(nav/link (r/route-for :dashboard/elements) "ELEMENTS")]
(header-link :dashboard/elements "ELEMENTS")]
[:li {:class (when icons? "current")}
(nav/link (r/route-for :dashboard/icons) "ICONS")]
(header-link :dashboard/icons "ICONS")]
[:li {:class (when colors? "current")}
(nav/link (r/route-for :dashboard/colors) "COLORS")]]
(header-link :dashboard/colors "COLORS")]]
(ui.u/user)])))
(def ^:static header
@ -34,4 +50,4 @@
{:render header-render
:name "header"
:mixins [rum/static
(rum/local {:section :projects})]}))
rum/reactive]}))