mirror of
https://github.com/penpot/penpot.git
synced 2025-02-09 00:28:20 -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)
|
;; --- 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
|
(mf/def app
|
||||||
:mixins [mx/reactive]
|
:mixins [mx/reactive]
|
||||||
|
|
||||||
|
@ -121,17 +108,12 @@
|
||||||
:settings/notifications)
|
:settings/notifications)
|
||||||
(mf/elem settings/settings {:route route})
|
(mf/elem settings/settings {:route route})
|
||||||
|
|
||||||
;; :settings/profile (mf/elem settings/settings {:section :profile})
|
(:dashboard/projects
|
||||||
;; :settings/password (mf/elem settings/settings {:section :password})
|
:dashboard/icons
|
||||||
;; :settings/notifications (mf/elem settings/notifications-page)
|
: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
|
:workspace/page
|
||||||
(let [project (uuid (get-in route [:params :path :project]))
|
(let [project (uuid (get-in route [:params :path :project]))
|
||||||
page (uuid (get-in route [:params :path :page]))]
|
page (uuid (get-in route [:params :path :page]))]
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
(ns uxbox.main.ui.dashboard
|
(ns uxbox.main.ui.dashboard
|
||||||
(:require
|
(:require
|
||||||
|
[cuerdas.core :as str]
|
||||||
[rumext.alpha :as mf]
|
[rumext.alpha :as mf]
|
||||||
|
[uxbox.util.data :refer [parse-int uuid-str?]]
|
||||||
[uxbox.main.ui.dashboard.header :refer [header]]
|
[uxbox.main.ui.dashboard.header :refer [header]]
|
||||||
[uxbox.main.ui.dashboard.projects :as projects]
|
[uxbox.main.ui.dashboard.projects :as projects]
|
||||||
;; [uxbox.main.ui.dashboard.elements :as elements]
|
;; [uxbox.main.ui.dashboard.elements :as elements]
|
||||||
|
@ -15,13 +17,27 @@
|
||||||
(def images-page images/images-page)
|
(def images-page images/images-page)
|
||||||
(def colors-page colors/colors-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
|
(mf/defc dashboard
|
||||||
[props]
|
{:wrap [mf/memo*]}
|
||||||
|
[{:keys [route] :as props}]
|
||||||
|
(let [{:keys [section] :as props} (parse-route route)]
|
||||||
[:main.dashboard-main
|
[:main.dashboard-main
|
||||||
(messages-widget)
|
(messages-widget)
|
||||||
(header)
|
(header) ;; TODO: pass section to header
|
||||||
(case (:section props)
|
(case section
|
||||||
:icons (icons/icons-page props)
|
:dashboard/icons (icons/icons-page props)
|
||||||
:images (images/images-page props)
|
:dashboard/images (images/images-page props)
|
||||||
:projects (projects/projects-page props)
|
:dashboard/projects (projects/projects-page props)
|
||||||
:colors (colors/colors-page props))])
|
:dashboard/colors (colors/colors-page props))]))
|
||||||
|
|
|
@ -61,8 +61,8 @@
|
||||||
(let [match (rt/match router path)]
|
(let [match (rt/match router path)]
|
||||||
(prn "on-navigate" path match)
|
(prn "on-navigate" path match)
|
||||||
(cond
|
(cond
|
||||||
(and (= path "") (nil? match))
|
;; (and (= path "") (nil? match))
|
||||||
(html-history/set-path! "/not-found")
|
;; (html-history/set-path! "/not-found")
|
||||||
|
|
||||||
(nil? match)
|
(nil? match)
|
||||||
(prn "TODO 404")
|
(prn "TODO 404")
|
||||||
|
|
Loading…
Add table
Reference in a new issue