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

Try to fix pagination (see #28)

This commit is contained in:
Arne Schlüter 2018-10-17 16:55:14 +02:00
commit 3ef4841c47
3 changed files with 11 additions and 10 deletions

View file

@ -6,10 +6,15 @@
"Concatenates all responses of one type of library to make paging through
it a bit easier."
[responses [_ kind]]
(->> (filter (fn [[[_ params] _]]
(let [sorted-albums (->> (filter (fn [[[_ params] _]]
(= kind (:type params))) responses)
(sort-by (fn [[[_ params] _]] (:offset params)))
(mapcat (fn [[_ vals]] (:album vals)))))
(map (comp :album val)))]
;; NOTE: we concatenate this manually to avoid duplication; we have to do
;; this because fetch more than conf/albums-per-page per page, otherwise we
;; can't know whether to show a link to the next page
(concat (mapcat (partial take conf/albums-per-page) (butlast sorted-albums))
(last sorted-albums))))
(re-frame/reg-sub
:library/complete

View file

@ -32,10 +32,6 @@
(let [num-pages (num-pages items per-page max-pages)
first-page? (= current-page 1)
last-page? (= current-page num-pages)]
(println "range"
(count items)
"num-pages"
num-pages)
[:nav.pagination {:role "pagination", :aria-label "pagination"}
[:a.pagination-previous (if first-page?
{:disabled true}
@ -69,7 +65,7 @@
{:keys [scan-status]}]
(let [library @(subscribe [:library/complete kind])
;; FIXME: vv Views shouldn't do calculations vv
visible (->> (drop (* (dec page) conf/albums-per-page) library)
visible (->> (drop (* (dec (int page)) conf/albums-per-page) library)
(take conf/albums-per-page))
url-fn #(url-for ::routes/library {:kind kind} {:page %})
pagination [pagination {:current-page (int page)

View file

@ -50,7 +50,7 @@
;; page through it faster
[:api/request "getAlbumList2" {:type kind
:size (* 3 conf/albums-per-page)
:offset (* page conf/albums-per-page)}]]
:offset (* (dec (int page)) conf/albums-per-page)}]]
[:routes/do-navigation [route-id {:kind "recent"} {:page 1}]]))
(defmethod -route-events ::artist.overview