diff --git a/src/cljs/airsonic_ui/components/library/subs.cljs b/src/cljs/airsonic_ui/components/library/subs.cljs index 0003278..7a0c908 100644 --- a/src/cljs/airsonic_ui/components/library/subs.cljs +++ b/src/cljs/airsonic_ui/components/library/subs.cljs @@ -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] _]] - (= kind (:type params))) responses) - (sort-by (fn [[[_ params] _]] (:offset params))) - (mapcat (fn [[_ vals]] (:album vals))))) + (let [sorted-albums (->> (filter (fn [[[_ params] _]] + (= kind (:type params))) responses) + (sort-by (fn [[[_ params] _]] (:offset params))) + (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 diff --git a/src/cljs/airsonic_ui/components/library/views.cljs b/src/cljs/airsonic_ui/components/library/views.cljs index 1a4c6b6..104f78c 100644 --- a/src/cljs/airsonic_ui/components/library/views.cljs +++ b/src/cljs/airsonic_ui/components/library/views.cljs @@ -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) diff --git a/src/cljs/airsonic_ui/routes.cljs b/src/cljs/airsonic_ui/routes.cljs index 3a178e8..0bffba9 100644 --- a/src/cljs/airsonic_ui/routes.cljs +++ b/src/cljs/airsonic_ui/routes.cljs @@ -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