mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-07 02:33:39 +02:00
Add pagination
This commit is contained in:
parent
096e1b4fb8
commit
5c66a1d5bf
4 changed files with 57 additions and 24 deletions
|
|
@ -1,26 +1,59 @@
|
||||||
(ns airsonic-ui.components.library.views
|
(ns airsonic-ui.components.library.views
|
||||||
(:require [airsonic-ui.routes :as routes :refer [url-for]]
|
(:require [airsonic-ui.routes :as routes :refer [url-for]]
|
||||||
[airsonic-ui.views.album :as album]))
|
[airsonic-ui.views.album :as album]
|
||||||
|
[airsonic-ui.helpers :refer [add-classes]]))
|
||||||
|
|
||||||
(defn tabs [items active-item]
|
(defn tabs [{:keys [items active-item]}]
|
||||||
[:div.tabs
|
[:div.tabs
|
||||||
[:ul (for [[idx [route label]] (map-indexed vector items)]
|
[:ul (for [[idx [route label]] (map-indexed vector items)]
|
||||||
(do
|
(let [[_ params _] route]
|
||||||
(println route label active-item)
|
^{:key idx} [:li (when (= params active-item)
|
||||||
^{:key idx} [:li (when (= route active-item)
|
|
||||||
{:class-name "is-active"})
|
{:class-name "is-active"})
|
||||||
[:a {:href (apply url-for route)} label]]))]])
|
[:a {:href (apply url-for route)} label]]))]])
|
||||||
|
|
||||||
|
(defn pagination
|
||||||
|
"Builds a pagination, calling `url-fn` for every rendered page link with the
|
||||||
|
page as its argument. When `max-pages` is `nil` an infinite pagination
|
||||||
|
will be rendered."
|
||||||
|
[{:keys [url-fn max-pages current-page]}]
|
||||||
|
[:nav.pagination.is-centered {:role "pagination", :aria-label "pagination"}
|
||||||
|
[:a.pagination-previous (if (> current-page 1)
|
||||||
|
{:href (url-fn (dec current-page))}
|
||||||
|
{:disabled true}) "Previous page"]
|
||||||
|
[:a.pagination-next (if (= max-pages current-page)
|
||||||
|
{:disabled true}
|
||||||
|
{:href (url-fn (inc current-page))}) "Next page"]
|
||||||
|
[:ul.pagination-list
|
||||||
|
(when (> current-page 3)
|
||||||
|
^{:key "ellipsis-before"} [:li>span.pagination-ellipsis "…"])
|
||||||
|
(for [page (range (max 1 (- current-page 2))
|
||||||
|
(if max-pages
|
||||||
|
(min (+ current-page 3) (inc max-pages))
|
||||||
|
(+ current-page 3)))]
|
||||||
|
(let [current-page? (= page current-page)]
|
||||||
|
^{:key page} [(cond-> :li>a.pagination-link
|
||||||
|
current-page? (add-classes :is-current))
|
||||||
|
(cond-> {:href (url-fn page), :aria-label (str "Page " page)}
|
||||||
|
(= page current-page) (assoc :aria-current "page")) page]))
|
||||||
|
(when (or (not max-pages) (< max-pages (- max-pages 3)))
|
||||||
|
^{:key "ellipsis-after"} [:li>span.pagination-ellipsis "…"])]])
|
||||||
|
|
||||||
(defn main [route {:keys [scan-status album-list]}]
|
(defn main [route {:keys [scan-status album-list]}]
|
||||||
(println scan-status "status")
|
(let [[_ {:keys [criteria]} {:keys [page] :or {page 1}}] route
|
||||||
[:div
|
pagination [pagination {:current-page (int page)
|
||||||
[:h2.title "Your library"]
|
:max-pages 5
|
||||||
(if (:count scan-status)
|
:url-fn #(url-for ::routes/library {:criteria criteria} {:page %})}]]
|
||||||
[:p.subtitle.is-5.has-text-grey "Containing " [:strong (:count scan-status)] " items"]
|
[:div
|
||||||
(when (:scanning scan-status)
|
[:h2.title "Your library"]
|
||||||
[:p.subtitle.is-5.has-text-grey "Scanning…"]))
|
(if (:count scan-status)
|
||||||
(let [items [[[::routes/library {:criteria "recent"} nil] "Recently played"]
|
[:p.subtitle.is-5.has-text-grey "Containing " [:strong (:count scan-status)] " items"]
|
||||||
[[::routes/library {:criteria "newest"} nil] "Newest additions"]
|
(when (:scanning scan-status)
|
||||||
[[::routes/library {:criteria "starred"} nil] "Starred"]]]
|
[:p.subtitle.is-5.has-text-grey "Scanning…"]))
|
||||||
[tabs items route])
|
(let [items [[[::routes/library {:criteria "recent"} nil] "Recently played"]
|
||||||
[album/listing (:album album-list)]])
|
[[::routes/library {:criteria "newest"} nil] "Newest additions"]
|
||||||
|
[[::routes/library {:criteria "starred"} nil] "Starred"]]]
|
||||||
|
[tabs {:items items :active-item {:criteria criteria}}])
|
||||||
|
pagination
|
||||||
|
[:section.section
|
||||||
|
[album/listing (:album album-list)]]
|
||||||
|
pagination]))
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,11 @@
|
||||||
(defmethod -route-events :default [route-id params query] nil)
|
(defmethod -route-events :default [route-id params query] nil)
|
||||||
|
|
||||||
(defmethod -route-events ::library
|
(defmethod -route-events ::library
|
||||||
[route-id {:keys [criteria]} query]
|
[route-id {:keys [criteria]} {:keys [page]}]
|
||||||
(if criteria
|
(if criteria
|
||||||
[[:api/request "getScanStatus"]
|
[[:api/request "getScanStatus"]
|
||||||
[:api/request "getAlbumList2" {:type criteria, :size 20}]]
|
[:api/request "getAlbumList2" {:type criteria, :size 20, :offset (* 20 (dec page))}]]
|
||||||
[:routes/do-navigation [route-id {:criteria "recent"} query]]))
|
[:routes/do-navigation [route-id {:criteria "recent"} {:page 1}]]))
|
||||||
|
|
||||||
(defmethod -route-events ::artist-view
|
(defmethod -route-events ::artist-view
|
||||||
[route-id params query]
|
[route-id params query]
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
(dispatch [::events/set-playback-mode (if (= playback-mode :shuffled)
|
(dispatch [::events/set-playback-mode (if (= playback-mode :shuffled)
|
||||||
:linear :shuffled)]))
|
:linear :shuffled)]))
|
||||||
|
|
||||||
(defn- advance-repeat-mode [current-mode]
|
(defn- toggle-repeat-mode [current-mode]
|
||||||
(let [modes (cycle '(:repeat-none :repeat-all :repeat-single))
|
(let [modes (cycle '(:repeat-none :repeat-all :repeat-single))
|
||||||
next-mode (->> (drop-while (partial not= current-mode) modes)
|
next-mode (->> (drop-while (partial not= current-mode) modes)
|
||||||
(second))]
|
(second))]
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
nil))]
|
nil))]
|
||||||
[:div.field.has-addons
|
[:div.field.has-addons
|
||||||
^{:key :shuffle-button} [shuffle-button {:on-click (toggle-shuffle playback-mode)} [icon :random]]
|
^{:key :shuffle-button} [shuffle-button {:on-click (toggle-shuffle playback-mode)} [icon :random]]
|
||||||
^{:key :repeat-button} [repeat-button {:on-click (advance-repeat-mode repeat-mode)} [icon :loop]]]))
|
^{:key :repeat-button} [repeat-button {:on-click (toggle-repeat-mode repeat-mode)} [icon :loop]]]))
|
||||||
|
|
||||||
(def logo-url "./img/airsonic-light-350x100.png")
|
(def logo-url "./img/airsonic-light-350x100.png")
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@
|
||||||
playlist @(subscribe [:audio/playlist])
|
playlist @(subscribe [:audio/playlist])
|
||||||
playback-status @(subscribe [:audio/playback-status])
|
playback-status @(subscribe [:audio/playback-status])
|
||||||
is-playing? @(subscribe [:audio/is-playing?])]
|
is-playing? @(subscribe [:audio/is-playing?])]
|
||||||
[:nav.navbar.is-fixed-bottom.playback-area
|
[:nav.navbar.is-fixed-bottom.audio-player
|
||||||
[:div.navbar-brand
|
[:div.navbar-brand
|
||||||
[:div.navbar-item
|
[:div.navbar-item
|
||||||
[:img {:src logo-url}]]]
|
[:img {:src logo-url}]]]
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
min-height: calc(100vh - 2.5rem)
|
min-height: calc(100vh - 2.5rem)
|
||||||
|
|
||||||
// bottom bar
|
// bottom bar
|
||||||
.playback-area
|
.audio-player
|
||||||
background: $dark
|
background: $dark
|
||||||
color: $light
|
color: $light
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue