mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-07 02:33:39 +02:00
Add tabs for newest and starred tracks
This commit is contained in:
parent
7653af5dd1
commit
2545ff3579
5 changed files with 40 additions and 20 deletions
21
src/cljs/airsonic_ui/components/library/views.cljs
Normal file
21
src/cljs/airsonic_ui/components/library/views.cljs
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
(ns airsonic-ui.components.library.views
|
||||||
|
(:require [airsonic-ui.routes :as routes :refer [url-for]]
|
||||||
|
[airsonic-ui.views.album :as album]))
|
||||||
|
|
||||||
|
(defn tabs [items active-item]
|
||||||
|
[:div.tabs
|
||||||
|
[:ul (for [[idx [route label]] (map-indexed vector items)]
|
||||||
|
(do
|
||||||
|
(println route label active-item)
|
||||||
|
^{:key idx} [:li (when (= route active-item)
|
||||||
|
{:class-name "is-active"})
|
||||||
|
[:a {:href (apply url-for route)} label]]))]])
|
||||||
|
|
||||||
|
(defn main [route {:keys [album-list]}]
|
||||||
|
[:div
|
||||||
|
[:h2.title "Your library"]
|
||||||
|
(let [items [[[::routes/library {:criteria "recent"} nil] "Recently played"]
|
||||||
|
[[::routes/library {:criteria "newest"} nil] "Newest additions"]
|
||||||
|
[[::routes/library {:criteria "starred"} nil] "Starred"]]]
|
||||||
|
[tabs items route])
|
||||||
|
[album/listing (:album album-list)]])
|
||||||
|
|
@ -113,7 +113,7 @@
|
||||||
(defn logged-in
|
(defn logged-in
|
||||||
[cofx _]
|
[cofx _]
|
||||||
(let [redirect (or (get-in cofx [:routes/from-query-param :redirect])
|
(let [redirect (or (get-in cofx [:routes/from-query-param :redirect])
|
||||||
[::routes/main])]
|
[::routes/library])]
|
||||||
{:dispatch [:routes/do-navigation redirect]
|
{:dispatch [:routes/do-navigation redirect]
|
||||||
:show-nav-bar nil}))
|
:show-nav-bar nil}))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,18 +7,20 @@
|
||||||
|
|
||||||
(defonce router
|
(defonce router
|
||||||
(r/router [["/" ::login]
|
(r/router [["/" ::login]
|
||||||
["/main" ::main]
|
["/library" ::library]
|
||||||
|
["/library/:criteria" ::library]
|
||||||
["/artist/:id" ::artist-view]
|
["/artist/:id" ::artist-view]
|
||||||
["/album/:id" ::album-view]
|
["/album/:id" ::album-view]
|
||||||
["/search" ::search]]))
|
["/search" ::search]]))
|
||||||
|
|
||||||
;; use this in views to construct a url
|
;; use this in views to construct a url
|
||||||
(defn url-for
|
(defn url-for
|
||||||
([k] (url-for k {}))
|
([k] (url-for k {} nil))
|
||||||
([k params] (str "#" (r/resolve router k params))))
|
([k params] (url-for k params nil))
|
||||||
|
([k params query] (str "#" (r/resolve router k params query))))
|
||||||
|
|
||||||
;; which routes need valid login credentials?
|
;; which routes need valid login credentials?
|
||||||
(def protected-routes #{::main ::artist-view ::album-view ::search})
|
(def protected-routes #{::library ::artist-view ::album-view ::search})
|
||||||
|
|
||||||
;; which data should be requested for which route? can either be a vector or a function returning a vector
|
;; which data should be requested for which route? can either be a vector or a function returning a vector
|
||||||
|
|
||||||
|
|
@ -28,10 +30,11 @@
|
||||||
|
|
||||||
(defmethod -route-events :default [route-id params query] nil)
|
(defmethod -route-events :default [route-id params query] nil)
|
||||||
|
|
||||||
(defmethod -route-events ::main
|
(defmethod -route-events ::library
|
||||||
[route-id params query]
|
[route-id {:keys [criteria]} query]
|
||||||
[:api/request "getAlbumList2" {:type "recent"
|
(if criteria
|
||||||
:size 18}])
|
[:api/request "getAlbumList2" {:type criteria, :size 18}]
|
||||||
|
[:routes/do-navigation [route-id {:criteria "recent"} query]]))
|
||||||
|
|
||||||
(defmethod -route-events ::artist-view
|
(defmethod -route-events ::artist-view
|
||||||
[route-id params query]
|
[route-id params query]
|
||||||
|
|
@ -97,7 +100,6 @@
|
||||||
credentials'(get-in context [:coeffects :db :credentials])]
|
credentials'(get-in context [:coeffects :db :credentials])]
|
||||||
(println "calling do-navigation with" route credentials')
|
(println "calling do-navigation with" route credentials')
|
||||||
(reset! credentials credentials')
|
(reset! credentials credentials')
|
||||||
(println "context" context)
|
|
||||||
(apply r/navigate! router route)
|
(apply r/navigate! router route)
|
||||||
(dissoc context :event)))))
|
(dissoc context :event)))))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@
|
||||||
[airsonic-ui.views.login :refer [login-form]]
|
[airsonic-ui.views.login :refer [login-form]]
|
||||||
[airsonic-ui.views.album :as album]
|
[airsonic-ui.views.album :as album]
|
||||||
[airsonic-ui.views.song :as song]
|
[airsonic-ui.views.song :as song]
|
||||||
[airsonic-ui.components.search.views :as search]))
|
[airsonic-ui.components.search.views :as search]
|
||||||
|
[airsonic-ui.components.library.views :as library]))
|
||||||
|
|
||||||
;; TODO: Find better names and places for these.
|
;; TODO: Find better names and places for these.
|
||||||
|
|
||||||
|
|
@ -26,11 +27,6 @@
|
||||||
[:div.content>p {:dangerouslySetInnerHTML {:__html (:biography artist-info)}}]
|
[:div.content>p {:dangerouslySetInnerHTML {:__html (:biography artist-info)}}]
|
||||||
[album/listing (:album artist)]])
|
[album/listing (:album artist)]])
|
||||||
|
|
||||||
(defn most-recent [{:keys [album-list]}]
|
|
||||||
[:div
|
|
||||||
[:h2.title "Recently played"]
|
|
||||||
[album/listing (:album album-list)]])
|
|
||||||
|
|
||||||
(defn sidebar [user]
|
(defn sidebar [user]
|
||||||
[:aside.menu.section
|
[:aside.menu.section
|
||||||
[search/form]
|
[search/form]
|
||||||
|
|
@ -53,6 +49,7 @@
|
||||||
|
|
||||||
(defn app [route-id params query]
|
(defn app [route-id params query]
|
||||||
(let [user @(subscribe [::subs/user])
|
(let [user @(subscribe [::subs/user])
|
||||||
|
;; TODO: Move this to a layer 3 subscription ↓
|
||||||
route-events @(subscribe [:routes/events-for-current-route])
|
route-events @(subscribe [:routes/events-for-current-route])
|
||||||
content @(subscribe [:api/route-data route-events])]
|
content @(subscribe [:api/route-data route-events])]
|
||||||
[:div
|
[:div
|
||||||
|
|
@ -63,7 +60,7 @@
|
||||||
[:section.section
|
[:section.section
|
||||||
[breadcrumbs content]
|
[breadcrumbs content]
|
||||||
(case route-id
|
(case route-id
|
||||||
::routes/main [most-recent content]
|
::routes/library [library/main [route-id params query] content]
|
||||||
::routes/artist-view [artist-detail content]
|
::routes/artist-view [artist-detail content]
|
||||||
::routes/album-view [album-detail content]
|
::routes/album-view [album-detail content]
|
||||||
::routes/search [search/results content])]]]
|
::routes/search [search/results content])]]]
|
||||||
|
|
|
||||||
|
|
@ -28,16 +28,16 @@
|
||||||
|
|
||||||
(defmethod breadcrumbs :artist [{:keys [artist]}]
|
(defmethod breadcrumbs :artist [{:keys [artist]}]
|
||||||
[bulma-breadcrumbs
|
[bulma-breadcrumbs
|
||||||
[(url-for ::routes/main) "Start"]
|
[(url-for ::routes/library) "Start"]
|
||||||
(:name artist)])
|
(:name artist)])
|
||||||
|
|
||||||
(defmethod breadcrumbs :album [{:keys [album]}]
|
(defmethod breadcrumbs :album [{:keys [album]}]
|
||||||
[bulma-breadcrumbs
|
[bulma-breadcrumbs
|
||||||
[(url-for ::routes/main) "Start"]
|
[(url-for ::routes/library) "Start"]
|
||||||
[(url-for ::routes/artist-view {:id (:artistId album)}) (:artist album)]
|
[(url-for ::routes/artist-view {:id (:artistId album)}) (:artist album)]
|
||||||
(:name album)])
|
(:name album)])
|
||||||
|
|
||||||
(defmethod breadcrumbs :search [_]
|
(defmethod breadcrumbs :search [_]
|
||||||
[bulma-breadcrumbs
|
[bulma-breadcrumbs
|
||||||
[(url-for ::routes/main) "Start"]
|
[(url-for ::routes/library) "Start"]
|
||||||
"Search"])
|
"Search"])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue