mirror of
https://github.com/penpot/penpot.git
synced 2025-04-13 07:21:40 -05:00
Move routes declaration into ui ns.
Leaving router as agnostic helpers impl.
This commit is contained in:
parent
718e7dc803
commit
d8dac5169f
5 changed files with 73 additions and 47 deletions
|
@ -5,7 +5,7 @@
|
|||
(let [start (System/nanoTime)]
|
||||
(b/build
|
||||
(b/inputs "src" "vendor")
|
||||
{:main 'uxbox.core
|
||||
{:main 'uxbox.main
|
||||
:parallel-build false
|
||||
:warnings {:ns-var-clash false}
|
||||
:output-to "resources/public/js/main.js"
|
||||
|
|
|
@ -5,24 +5,49 @@
|
|||
{:figwheel-options {:css-dirs ["resources/public/css"]
|
||||
:server-port 3449
|
||||
:server-ip "0.0.0.0"}
|
||||
:build-ids ["dev"]
|
||||
:build-ids ["main", "preview"]
|
||||
:all-builds
|
||||
[{:id "dev"
|
||||
[{:id "main"
|
||||
:figwheel {:on-jsload "uxbox.ui/init"}
|
||||
:source-paths ["src" "vendor"]
|
||||
:compiler
|
||||
{:main 'uxbox.core
|
||||
{:main 'uxbox.main
|
||||
:asset-path "js"
|
||||
:parallel-build false
|
||||
:optimizations :none
|
||||
;; :closure-defines {"uxbox.repo.core.url"
|
||||
;; "https://test.uxbox.io/api"}
|
||||
:closure-defines {"uxbox.repo.core.url"
|
||||
"https://test.uxbox.io/api"}
|
||||
"http://localhost:6060/api"}
|
||||
:warnings {:ns-var-clash false}
|
||||
:pretty-print true
|
||||
:language-in :ecmascript6
|
||||
:language-out :ecmascript5
|
||||
:output-to "resources/public/js/main.js"
|
||||
:output-dir "resources/public/js"
|
||||
:verbose true}}]})
|
||||
:verbose true}}
|
||||
|
||||
(ra/cljs-repl "dev")
|
||||
#_{:id "preview"
|
||||
;; :figwheel {:on-jsload "uxbox.ui/init"}
|
||||
:source-paths ["src" "vendor"]
|
||||
:compiler
|
||||
{:main 'uxbox.core
|
||||
:asset-path "js"
|
||||
:parallel-build false
|
||||
:optimizations :none
|
||||
;; :closure-defines {"uxbox.repo.core.url"
|
||||
;; "https://test.uxbox.io/api"}
|
||||
:closure-defines {"uxbox.repo.core.url"
|
||||
"http://localhost:6060/api"}
|
||||
:warnings {:ns-var-clash false}
|
||||
:pretty-print true
|
||||
:language-in :ecmascript6
|
||||
:language-out :ecmascript5
|
||||
:output-to "resources/public/preview/js/main.js"
|
||||
:output-dir "resources/public/preview/js"
|
||||
:verbose true}}
|
||||
|
||||
|
||||
]})
|
||||
|
||||
(ra/cljs-repl "main")
|
||||
|
|
|
@ -5,11 +5,9 @@
|
|||
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.core
|
||||
(ns uxbox.main
|
||||
(:require-macros [uxbox.util.syntax :refer [define-once]])
|
||||
(:require [beicon.core :as rx]
|
||||
[uxbox.state :as st]
|
||||
[uxbox.router :as rt]
|
||||
(:require [uxbox.state :as st]
|
||||
[uxbox.rstore :as rs]
|
||||
[uxbox.ui :as ui]))
|
||||
|
||||
|
@ -17,5 +15,5 @@
|
|||
|
||||
(define-once :setup
|
||||
(st/init)
|
||||
(rt/init)
|
||||
(ui/init-routes)
|
||||
(ui/init))
|
|
@ -14,7 +14,8 @@
|
|||
|
||||
(enable-console-print!)
|
||||
|
||||
(defonce +router+ (volatile! nil))
|
||||
(defonce +router+ nil)
|
||||
(defonce +routes+ nil)
|
||||
|
||||
;; --- Update Location (Event)
|
||||
|
||||
|
@ -42,7 +43,7 @@
|
|||
(let [loc (merge {:handler id}
|
||||
(when params
|
||||
{:route-params params}))]
|
||||
(bidi.router/set-location! @+router+ loc))))
|
||||
(bidi.router/set-location! +router+ loc))))
|
||||
|
||||
(defn navigate
|
||||
([id] (navigate id nil))
|
||||
|
@ -50,40 +51,15 @@
|
|||
{:pre [(keyword? id)]}
|
||||
(Navigate. id params)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Router declaration
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(def ^:private page-route
|
||||
[[bidi/uuid :project-uuid] "/" [bidi/uuid :page-uuid]])
|
||||
|
||||
(def routes
|
||||
["/" [["auth/login" :auth/login]
|
||||
["auth/register" :auth/register]
|
||||
["auth/recovery/request" :auth/recovery-request]
|
||||
[["auth/recovery/token/" :token] :auth/recovery]
|
||||
|
||||
["settings/" [["profile" :settings/profile]
|
||||
["password" :settings/password]
|
||||
["notifications" :settings/notifications]]]
|
||||
|
||||
["dashboard/" [["projects" :dashboard/projects]
|
||||
["elements" :dashboard/elements]
|
||||
["icons" :dashboard/icons]
|
||||
["images" :dashboard/images]
|
||||
["colors" :dashboard/colors]]]
|
||||
["workspace/" [[page-route :workspace/page]]]]])
|
||||
;; --- Public Api
|
||||
|
||||
(defn init
|
||||
[]
|
||||
[routes]
|
||||
(let [opts {:on-navigate #(rs/emit! (update-location %))
|
||||
:default-location {:handler :auth/login}}
|
||||
router (bidi.router/start-router! routes opts)]
|
||||
(vreset! +router+ router)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Public Api
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(set! +routes+ routes)
|
||||
(set! +router+ router)))
|
||||
|
||||
(defn go
|
||||
"Redirect the user to other url."
|
||||
|
@ -94,6 +70,6 @@
|
|||
"Given a location handler and optional parameter map, return the URI
|
||||
for such handler and parameters."
|
||||
([id]
|
||||
(bidi/path-for routes id))
|
||||
(bidi/path-for +routes+ id))
|
||||
([id params]
|
||||
(apply bidi/path-for routes id (into [] (mapcat (fn [[k v]] [k v])) params))))
|
||||
(apply bidi/path-for +routes+ id (into [] (mapcat (fn [[k v]] [k v])) params))))
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
|
||||
(ns uxbox.ui
|
||||
(:require [sablono.core :as html :refer-macros [html]]
|
||||
[bidi.bidi :as bidi]
|
||||
[promesa.core :as p]
|
||||
[beicon.core :as rx]
|
||||
[goog.dom :as gdom]
|
||||
[rum.core :as rum]
|
||||
[lentes.core :as l]
|
||||
[uxbox.state :as st]
|
||||
[uxbox.router :as r]
|
||||
[uxbox.router :as rt]
|
||||
[uxbox.rstore :as rs]
|
||||
[uxbox.locales :refer (tr)]
|
||||
[uxbox.data.projects :as dp]
|
||||
|
@ -78,7 +79,7 @@
|
|||
location (:id route)
|
||||
params (:params route)]
|
||||
(if (and (restricted? location) (not auth))
|
||||
(do (p/schedule 0 #(r/go :auth/login)) nil)
|
||||
(do (p/schedule 0 #(rt/go :auth/login)) nil)
|
||||
(case location
|
||||
:auth/login (auth/login-page)
|
||||
:auth/register (auth/register-page)
|
||||
|
@ -125,8 +126,34 @@
|
|||
:name "loader"
|
||||
:mixins [rum/reactive mx/static]}))
|
||||
|
||||
;; --- Routes
|
||||
|
||||
(def ^:private page-route
|
||||
[[bidi/uuid :project-uuid] "/" [bidi/uuid :page-uuid]])
|
||||
|
||||
(def routes
|
||||
["/" [["auth/login" :auth/login]
|
||||
["auth/register" :auth/register]
|
||||
["auth/recovery/request" :auth/recovery-request]
|
||||
[["auth/recovery/token/" :token] :auth/recovery]
|
||||
|
||||
["settings/" [["profile" :settings/profile]
|
||||
["password" :settings/password]
|
||||
["notifications" :settings/notifications]]]
|
||||
|
||||
["dashboard/" [["projects" :dashboard/projects]
|
||||
["elements" :dashboard/elements]
|
||||
["icons" :dashboard/icons]
|
||||
["images" :dashboard/images]
|
||||
["colors" :dashboard/colors]]]
|
||||
["workspace/" [[page-route :workspace/page]]]]])
|
||||
|
||||
;; --- Main Entry Point
|
||||
|
||||
(defn init-routes
|
||||
[]
|
||||
(rt/init routes))
|
||||
|
||||
(defn init
|
||||
[]
|
||||
(let [app-dom (gdom/getElement "app")
|
||||
|
|
Loading…
Add table
Reference in a new issue