mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-06 18:33:38 +02:00
Implement artist view
This commit is contained in:
parent
00e2cf656c
commit
58176adffc
3 changed files with 42 additions and 24 deletions
|
|
@ -7,15 +7,15 @@
|
|||
(def router
|
||||
(r/router [["/" ::login]
|
||||
["/hello" ::main]
|
||||
["/album/:id" ::album-view]
|
||||
["/artist/:id" ::artist-view]]))
|
||||
["/artist/:id" ::artist-view]
|
||||
["/album/:id" ::album-view]]))
|
||||
|
||||
; use this in views to construct a url
|
||||
(defn url-for [k params]
|
||||
(str "#" (r/resolve router k params)))
|
||||
|
||||
; which routes need valid login credentials?
|
||||
(def protected-routes #{::main ::album-view})
|
||||
(def protected-routes #{::main ::artist-view ::album-view})
|
||||
|
||||
; which data should be requested for which route? can either be a vector or a function returning a vector
|
||||
|
||||
|
|
@ -29,9 +29,13 @@
|
|||
[route-id params query]
|
||||
[:api-request "getAlbumList2" :albumList2 {:type "recent"}])
|
||||
|
||||
(defmethod route-data ::artist-view
|
||||
[route-id params query]
|
||||
[:api-request "getArtist" :artist (select-keys params [:id])])
|
||||
|
||||
(defmethod route-data ::album-view
|
||||
[route-id params query]
|
||||
[:api-request "getAlbum" :album {:id (:id params)}])
|
||||
[:api-request "getAlbum" :album (select-keys params [:id])])
|
||||
|
||||
;; shouldn't need to change anything below
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,29 @@
|
|||
[:div
|
||||
[:button {:on-click #(dispatch [::events/authenticate @user @pass @server])} "Submit"]]])))
|
||||
|
||||
;; album list (start page)
|
||||
;; single album
|
||||
|
||||
(defn song-item [songs song]
|
||||
(let [artist-id (:artistId song)]
|
||||
[:div
|
||||
[:a
|
||||
(when artist-id {:href (routes/url-for ::routes/artist-view {:id artist-id})})
|
||||
(:artist song)]
|
||||
" - "
|
||||
[:a
|
||||
{:href "#" :on-click (fn [e]
|
||||
(.preventDefault e)
|
||||
(dispatch [::events/play-songs songs song]))}
|
||||
(:title song)]]))
|
||||
|
||||
(defn album-detail [content]
|
||||
[:div
|
||||
[:h2 (str (:artist content) " - " (:name content))]
|
||||
(let [songs (:song content)]
|
||||
[:ul (for [[idx song] (map-indexed vector songs)]
|
||||
[:li {:key idx} [song-item songs song]])])])
|
||||
|
||||
;; single artist
|
||||
|
||||
(defn album-item [album]
|
||||
(let [{:keys [artist artistId name coverArt year id]} album]
|
||||
|
|
@ -49,29 +71,20 @@
|
|||
;; link to album
|
||||
[:a {:href (routes/url-for ::routes/album-view {:id id})} name] (when year (str " (" year ")"))]))
|
||||
|
||||
;; TODO: album-list shouldn't know about the structure of content and should just get a list
|
||||
(defn album-list [content]
|
||||
(defn artist-detail [content]
|
||||
[:div
|
||||
[:h2 (str "Recently played")]
|
||||
[:h2 (:name content)]
|
||||
[:p (:albumCount content) " items"]
|
||||
[:ul (for [[idx album] (map-indexed vector (:album content))]
|
||||
[:li {:key idx} [album-item album]])]])
|
||||
|
||||
;; single album
|
||||
;; TODO: album-list shouldn't know about the structure of content and should just get a list
|
||||
|
||||
(defn song-item [songs song]
|
||||
[:div (str (:artist song) " - ")
|
||||
[:a
|
||||
{:on-click #(dispatch [::events/play-songs songs song])}
|
||||
(:title song)]])
|
||||
|
||||
(defn song-list [songs]
|
||||
[:ul (for [[idx song] (map-indexed vector songs)]
|
||||
[:li {:key idx} [song-item songs song]])])
|
||||
|
||||
(defn album-detail [content]
|
||||
(defn most-recent [content]
|
||||
[:div
|
||||
[:h2 (str (:artist content) " - " (:name content))]
|
||||
[song-list (:song content)]])
|
||||
[:h2 "Recently played"]
|
||||
[:ul (for [[idx album] (map-indexed vector (:album content))]
|
||||
[:li {:key idx} [album-item album]])]])
|
||||
|
||||
;; currently playing / coming next / audio controls...
|
||||
|
||||
|
|
@ -104,7 +117,8 @@
|
|||
[:div
|
||||
[:span (str "Currently logged in as " (:u login))]
|
||||
(case route
|
||||
::routes/main [album-list content]
|
||||
::routes/main [most-recent content]
|
||||
::routes/artist-view [artist-detail content]
|
||||
::routes/album-view [album-detail content])
|
||||
[:a {:on-click #(dispatch [::events/initialize-db]) :href "#"} "Logout"]
|
||||
[bottom-bar]]))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue