From ac56423d109a895d7bdad465ebab63ed2f7f1731 Mon Sep 17 00:00:00 2001 From: Miguel Ángel Moreno Date: Fri, 19 Apr 2024 16:30:21 +0200 Subject: fix: fix infinite search pagination --- src/frontend/tubo/events.cljs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/frontend/tubo/events.cljs b/src/frontend/tubo/events.cljs index 5aecfec..c237b1c 100644 --- a/src/frontend/tubo/events.cljs +++ b/src/frontend/tubo/events.cljs @@ -354,12 +354,16 @@ (rf/reg-event-db ::load-paginated-search-results (fn [db [_ res]] - (-> db - (update-in [:search-results :items] #(apply conj %1 %2) - (:items (js->clj res :keywordize-keys true))) - (assoc-in [:search-results :next-page] - (:next-page (js->clj res :keywordize-keys true))) - (assoc :show-pagination-loading false)))) + (let [search-res (js->clj res :keywordize-keys true)] + (if (empty? (:items search-res)) + (-> db + (assoc-in [:search-results :next-page] nil) + (assoc :show-pagination-loading false)) + (-> db + (update-in [:search-results :items] #(apply conj %1 %2) + (:items search-res)) + (assoc-in [:search-results :next-page] (:next-page search-res)) + (assoc :show-pagination-loading false)))))) (rf/reg-event-fx ::search-pagination -- cgit v1.2.3