mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 07:29:08 -05:00
🔧 Simplify dashboard related route handlers.
This commit is contained in:
parent
5c4f88221c
commit
d34fc2512f
3 changed files with 32 additions and 34 deletions
|
@ -83,19 +83,6 @@
|
|||
|
||||
;; --- Main App (Component)
|
||||
|
||||
(defn- parse-dashboard-params
|
||||
[route section]
|
||||
(let [{:keys [id type]} (get-in route [:params :query])
|
||||
id (cond
|
||||
(str/digits? id) (parse-int id)
|
||||
(uuid-str? id) (uuid id)
|
||||
:else nil)
|
||||
type (when (str/alpha? type) (keyword type))]
|
||||
#js {:section section
|
||||
:id id
|
||||
:type type}))
|
||||
|
||||
|
||||
(mf/def app
|
||||
:mixins [mx/reactive]
|
||||
|
||||
|
@ -121,17 +108,12 @@
|
|||
:settings/notifications)
|
||||
(mf/elem settings/settings {:route route})
|
||||
|
||||
;; :settings/profile (mf/elem settings/settings {:section :profile})
|
||||
;; :settings/password (mf/elem settings/settings {:section :password})
|
||||
;; :settings/notifications (mf/elem settings/notifications-page)
|
||||
(:dashboard/projects
|
||||
:dashboard/icons
|
||||
:dashboard/images
|
||||
:dashboard/colors)
|
||||
(mf/elem dashboard/dashboard {:route route})
|
||||
|
||||
:dashboard/projects (mf/elem dashboard/dashboard {:section :projects})
|
||||
:dashboard/icons (->> (parse-dashboard-params route :icons)
|
||||
(mf/element dashboard/dashboard))
|
||||
:dashboard/images (->> (parse-dashboard-params route :images)
|
||||
(mf/element dashboard/dashboard))
|
||||
:dashboard/colors (->> (parse-dashboard-params route :colors)
|
||||
(mf/element dashboard/dashboard))
|
||||
:workspace/page
|
||||
(let [project (uuid (get-in route [:params :path :project]))
|
||||
page (uuid (get-in route [:params :path :page]))]
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
(ns uxbox.main.ui.dashboard
|
||||
(:require
|
||||
[cuerdas.core :as str]
|
||||
[rumext.alpha :as mf]
|
||||
[uxbox.util.data :refer [parse-int uuid-str?]]
|
||||
[uxbox.main.ui.dashboard.header :refer [header]]
|
||||
[uxbox.main.ui.dashboard.projects :as projects]
|
||||
;; [uxbox.main.ui.dashboard.elements :as elements]
|
||||
|
@ -15,13 +17,27 @@
|
|||
(def images-page images/images-page)
|
||||
(def colors-page colors/colors-page)
|
||||
|
||||
(defn- parse-route
|
||||
[{:keys [params data] :as route}]
|
||||
(let [{:keys [id type]} (:query params)
|
||||
id (cond
|
||||
(str/digits? id) (parse-int id)
|
||||
(uuid-str? id) (uuid id)
|
||||
:else nil)
|
||||
type (when (str/alpha? type) (keyword type))]
|
||||
{:section (:name data)
|
||||
:type type
|
||||
:id id}))
|
||||
|
||||
(mf/defc dashboard
|
||||
[props]
|
||||
[:main.dashboard-main
|
||||
(messages-widget)
|
||||
(header)
|
||||
(case (:section props)
|
||||
:icons (icons/icons-page props)
|
||||
:images (images/images-page props)
|
||||
:projects (projects/projects-page props)
|
||||
:colors (colors/colors-page props))])
|
||||
{:wrap [mf/memo*]}
|
||||
[{:keys [route] :as props}]
|
||||
(let [{:keys [section] :as props} (parse-route route)]
|
||||
[:main.dashboard-main
|
||||
(messages-widget)
|
||||
(header) ;; TODO: pass section to header
|
||||
(case section
|
||||
:dashboard/icons (icons/icons-page props)
|
||||
:dashboard/images (images/images-page props)
|
||||
:dashboard/projects (projects/projects-page props)
|
||||
:dashboard/colors (colors/colors-page props))]))
|
||||
|
|
|
@ -61,8 +61,8 @@
|
|||
(let [match (rt/match router path)]
|
||||
(prn "on-navigate" path match)
|
||||
(cond
|
||||
(and (= path "") (nil? match))
|
||||
(html-history/set-path! "/not-found")
|
||||
;; (and (= path "") (nil? match))
|
||||
;; (html-history/set-path! "/not-found")
|
||||
|
||||
(nil? match)
|
||||
(prn "TODO 404")
|
||||
|
|
Loading…
Add table
Reference in a new issue