From 03ab5b05398215e08dd0e4859decd709cbfb178a Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Fri, 19 Jan 2018 15:41:33 +0200 Subject: [PATCH] Pagination: add cursor pointer for buttons; scroll to top when changing page --- src/cljs/commiteth/activity.cljs | 1 + src/cljs/commiteth/bounties.cljs | 5 +++-- src/cljs/commiteth/handlers.cljs | 24 ++++++++++++++++++------ src/less/style.less | 1 + 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/cljs/commiteth/activity.cljs b/src/cljs/commiteth/activity.cljs index 69b4d34..0d199dd 100644 --- a/src/cljs/commiteth/activity.cljs +++ b/src/cljs/commiteth/activity.cljs @@ -59,6 +59,7 @@ (defn activity-list [activity-page-data] [:div.ui.container.activity-container + {:id "activity-container"} (if (empty? (:items activity-page-data)) [:div.view-no-data-container [:p "No recent activity yet"]] diff --git a/src/cljs/commiteth/bounties.cljs b/src/cljs/commiteth/bounties.cljs index 26957e3..ebe63d2 100644 --- a/src/cljs/commiteth/bounties.cljs +++ b/src/cljs/commiteth/bounties.cljs @@ -47,15 +47,16 @@ (defn bounties-list [{:keys [items item-count page-number total-count] :as bounty-page-data}] [:div.ui.container.open-bounties-container + {:id "open-bounties-container"} [:div.open-bounties-header "Bounties"] (if (empty? items) [:div.view-no-data-container [:p "No recent activity yet"]] - [:div + [:div (let [left (inc (* (dec page-number) items-per-page)) right (dec (+ left item-count))] [:div.item-counts-label - [:span (str "Showing " left "-" right " of " total-count)]]) + [:span (str "Showing " left "-" right " of " total-count)]]) (display-data-page bounty-page-data bounty-item :set-bounty-page-number)])]) (defn bounties-page [] diff --git a/src/cljs/commiteth/handlers.cljs b/src/cljs/commiteth/handlers.cljs index 1cf2562..f50ad77 100644 --- a/src/cljs/commiteth/handlers.cljs +++ b/src/cljs/commiteth/handlers.cljs @@ -6,6 +6,7 @@ reg-fx inject-cofx]] [ajax.core :refer [GET POST]] + [clojure.browser.dom :as dom :refer [get-element]] [cuerdas.core :as str] [cljs-web3.core :as web3] [cljs-web3.eth :as web3-eth] @@ -38,6 +39,15 @@ (println "redirecting to" path) (set! (.-pathname js/location) path))) +(reg-fx + :bounty-scroll-pos + (fn [scroll-pos] + (.scrollIntoView (get-element "open-bounties-container")) )) + +(reg-fx + :activity-scroll-pos + (fn [scroll-pos] + (.scrollIntoView (get-element "activity-container")))) (reg-event-fx :initialize-db @@ -68,15 +78,17 @@ (fn [db [_ page]] (assoc db :page page))) -(reg-event-db +(reg-event-fx :set-bounty-page-number - (fn [db [_ page]] - (assoc db :bounty-page-number page))) + (fn [{:keys [db]} [_ page]] + {:db (assoc db :bounty-page-number page) + :bounty-scroll-pos 0})) -(reg-event-db +(reg-event-fx :set-activity-page-number - (fn [db [_ page]] - (assoc db :activity-page-number page))) + (fn [{:keys [db]} [_ page]] + {:db (assoc db :activity-page-number page) + :activity-scroll-pos 0})) (reg-event-fx :set-flash-message diff --git a/src/less/style.less b/src/less/style.less index c21473f..145aca5 100644 --- a/src/less/style.less +++ b/src/less/style.less @@ -887,6 +887,7 @@ body { flex: none; align-items: center; justify-content: center; + cursor: pointer; } .grayed-out {