mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-06 18:33:38 +02:00
Move navigation to effect
This commit is contained in:
parent
fe0e250648
commit
6117b921a6
6 changed files with 63 additions and 46 deletions
|
|
@ -1,14 +1,34 @@
|
|||
(ns airsonic-ui.routes
|
||||
(:require [bide.core :as r]))
|
||||
(:require [bide.core :as r]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
;; routing is started in core.cljs
|
||||
(def default-route ::login)
|
||||
|
||||
(def default ::login)
|
||||
(def routes
|
||||
[["/" ::login]
|
||||
["/hello" ::main]])
|
||||
|
||||
(def router
|
||||
(r/router [["/" ::login]
|
||||
["/hello" ::main]]))
|
||||
(def protected-routes #{::main})
|
||||
|
||||
;; routes that need valid credentials
|
||||
(defn is-authorized? [login route]
|
||||
(or (not (protected-routes route)) login))
|
||||
|
||||
(def protected #{::main})
|
||||
;; shouldn't need to change this
|
||||
|
||||
;; TODO: This is kind of ugly because at the moment r/navigate! is called twice.
|
||||
;; the order is click -> hash-change -> {:navigate [bla] :db [bla]} -> (hash-change) -> ...
|
||||
|
||||
(defn start-routing!
|
||||
"Registers a :navigate effect that can be used for navigation; opts will be
|
||||
passed to bide.core/start!"
|
||||
[opts]
|
||||
(let [router (r/router routes)]
|
||||
(re-frame/reg-fx
|
||||
:navigate
|
||||
(fn [[login route-id params query]]
|
||||
(if (is-authorized? login route-id)
|
||||
(r/navigate! router route-id params query)
|
||||
(do ;; 403 gets a special event
|
||||
(println "Not authorized to navigate to " route-id)
|
||||
(re-frame/dispatch [::forbidden-route])))))
|
||||
(r/start! router opts)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue