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

Clean up the pagination function a bit

This commit is contained in:
Arne Schlüter 2018-10-17 16:04:45 +02:00
commit ecded256fc

View file

@ -18,9 +18,7 @@
;; :max-pages nil ;; :max-pages nil
;; :url-fn generate-url ;; :url-fn generate-url
;; :current-page 0 ;; :current-page 0
;; :items [,,,] ;; :items [,,,]}]
;; :on-change (fn [current-page items]
;; (reset! current-items items))}]
(defn num-pages [items per-page max-pages] (defn num-pages [items per-page max-pages]
(min (Math/ceil (/ (count items) per-page)) max-pages)) (min (Math/ceil (/ (count items) per-page)) max-pages))
@ -29,7 +27,7 @@
"Builds a pagination, calling `url-fn` for every rendered page link with the "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 page as its argument. When `max-pages` is `nil` an infinite pagination
will be rendered." will be rendered."
[{:keys [items per-page max-pages current-page url-fn on-change] [{:keys [items per-page max-pages current-page url-fn]
:or {max-pages (.-MAX_VALUE js/Number)}}] :or {max-pages (.-MAX_VALUE js/Number)}}]
(let [num-pages (num-pages items per-page max-pages) (let [num-pages (num-pages items per-page max-pages)
first-page? (= current-page 1) first-page? (= current-page 1)
@ -54,7 +52,7 @@
^{:key page} [(cond-> :li>a.pagination-link ^{:key page} [(cond-> :li>a.pagination-link
current-page? (add-classes :is-current)) current-page? (add-classes :is-current))
(cond-> {:href (url-fn page), :aria-label (str "Page " page)} (cond-> {:href (url-fn page), :aria-label (str "Page " page)}
(= page current-page) (assoc :aria-current "page")) page])) current-page? (assoc :aria-current "page")) page]))
(when (< current-page (- num-pages 2)) (when (< current-page (- num-pages 2))
^{:key "ellipsis-after"} [:li>span.pagination-ellipsis "…"])]])) ^{:key "ellipsis-after"} [:li>span.pagination-ellipsis "…"])]]))