1
0
Fork 0
mirror of https://github.com/heyarne/airsonic-ui.git synced 2026-05-06 18:33:38 +02:00

Make code a bit nicer to read / more idiomatic in some places

This commit is contained in:
Arne Schlüter 2018-04-22 01:00:40 +02:00
commit 491c172ae7
3 changed files with 26 additions and 32 deletions

View file

@ -91,9 +91,9 @@
(fn [{:keys [db]} [_ route params query]]
;; all the naviagation logic is in routes.cljs; all we need to do here
;; is say what actually happens once we've navigated succesfully
(println "routes/route-data" (routes/data-for route params query))
(println "routes/route-data" (routes/route-data route params query))
{:db (assoc db :current-route [route params query])
:dispatch (routes/data-for route params query)}))
:dispatch (routes/route-data route params query)}))
(re-frame/reg-event-fx
::routes/unauthorized

View file

@ -18,21 +18,20 @@
(def protected-routes #{::main ::album-view})
; which data should be requested for which route? can either be a vector or a function returning a vector
(def route-data
{::main [:api-request "getAlbumList2" :albumList2 {:type "recent"}]
::album-view (fn [route-id params _]
[:api-request "getAlbum" :album {:id (:id params)}])})
(defmulti route-data
"Returns the events that take care of correct data being fetched."
(fn [route-id & _] route-id))
(defn data-for
"Wrapper around route-data so we can call it like a function no matter whether
the value associated with the route key is a function or not."
[route params query]
(if-let [route-data' (route-data route)]
(if (vector? route-data')
route-data'
(route-data' route params query))
[]))
(defmethod route-data :default [route-id params query] []) ; no data
(defmethod route-data ::main
[route-id params query]
[:api-request "getAlbumList2" :albumList2 {:type "recent"}])
(defmethod route-data ::album-view
[route-id params query]
[:api-request "getAlbum" :album {:id (:id params)}])
;; shouldn't need to change anything below
@ -40,17 +39,17 @@
;; holding credentials, which is necessary to restrict certain routes, and the
;; last one is used for actual navigation
(def login (atom nil))
(def credentials (atom nil))
(re-frame/reg-fx
::set-credentials
(fn [credentials]
(reset! login credentials)))
(fn [credentials']
(reset! credentials credentials')))
(re-frame/reg-fx
::unset-credentials
(fn [credentials]
(reset! login nil)))
(fn []
(reset! credentials nil)))
(re-frame/reg-fx
::navigate
@ -59,7 +58,7 @@
(r/navigate! router route-id params query)))
(defn can-access? [route]
(or (not (protected-routes route)) @login))
(or (not (protected-routes route)) @credentials))
(defn on-navigate
[route-id params query]

View file

@ -38,11 +38,8 @@
(defn album-list [content]
[:div
[:h2 (str "Recently played")]
[:ul
(map-indexed
(fn [idx album]
[:li {:key idx} [album-item album]])
(:album content))]])
[:ul (for [[idx album] (map-indexed vector (:album content))]
[:li {:key idx} [album-item album]])]])
;; single album
@ -53,10 +50,8 @@
(:title song)]])
(defn song-list [songs]
[:ul
(map-indexed
(fn [idx song] [:li {:key idx} [song-item song]])
songs)])
[:ul (for [[idx song] (map-indexed vector songs)]
[:li {:key idx} [song-item song]])])
(defn album-detail [content]
[:div