From bdbdc2e2d23dee4f4fc54ba37591992fd8ec333b Mon Sep 17 00:00:00 2001 From: pablodip Date: Thu, 18 Jan 2018 05:45:42 +0100 Subject: [PATCH] add some bounty sorting --- src/cljs/commiteth/bounties.cljs | 62 +++++++++++++++------------ src/cljs/commiteth/db.cljs | 23 ++++++---- src/cljs/commiteth/handlers.cljs | 5 +++ src/cljs/commiteth/subscriptions.cljs | 7 +-- src/less/style.less | 12 +++++- 5 files changed, 67 insertions(+), 42 deletions(-) diff --git a/src/cljs/commiteth/bounties.cljs b/src/cljs/commiteth/bounties.cljs index 6c6c91e..7da81fa 100644 --- a/src/cljs/commiteth/bounties.cljs +++ b/src/cljs/commiteth/bounties.cljs @@ -2,7 +2,9 @@ (:require [reagent.core :as r] [re-frame.core :as rf] [commiteth.common :refer [moment-timestamp - issue-url]])) + issue-url]] + [commiteth.handlers :as handlers] + [commiteth.db :as db])) (defn bounty-item [bounty] @@ -60,40 +62,44 @@ (defn bounties-filters [] [:div.open-bounties-filter [bounties-filter "Value"] - [bounties-filter "Type"] - [bounties-filter "Language"] + [bounties-filter "Currency"] [bounties-filter "Date"] - [bounties-filter "More"]]) + [bounties-filter "Owner"]]) (defn bounties-sort [] (let [open? (r/atom false)] (fn [] - [:div.open-bounties-sort - {:tab-index 0 - :on-blur #(reset! open? false)} - [:div.open-bounties-sort-element - {:on-click #(swap! open? not)} - "Most Recent" - [:div.icon-forward-white-box - [:img - {:src "icon-forward-white.svg"}]]] - (when @open? - [:div.open-bounties-sort-element-tooltip - "TOOLTIP"])]))) + (let [current-sorting (rf/subscribe [::db/bounty-sorting-type])] + [:div.open-bounties-sort + {:tab-index 0 + :on-blur #(reset! open? false)} + [:div.open-bounties-sort-element + {:on-click #(swap! open? not)} + (db/bounty-sorting-types @current-sorting) + [:div.icon-forward-white-box + [:img + {:src "icon-forward-white.svg"}]]] + (when @open? + [:div.open-bounties-sort-element-tooltip + (for [[sorting-type sorting-name] db/bounty-sorting-types] + [:div.open-bounties-sort-type + {:on-click #(do + (reset! open? false) + (rf/dispatch [::handlers/set-bounty-sorting-type sorting-type]))} + sorting-name])])])))) (defn bounties-list [open-bounties] - (let [order (rf/subscribe [:bounties-order])] - [:div.ui.container.open-bounties-container - [:div.open-bounties-header "Bounties"] - [:div.open-bounties-filter-and-sort - [bounties-filters] - [bounties-sort]] - (if (empty? open-bounties) - [:div.view-no-data-container - [:p "No recent activity yet"]] - (into [:div.ui.items] - (for [bounty open-bounties] - [bounty-item bounty])))])) + [:div.ui.container.open-bounties-container + [:div.open-bounties-header "Bounties"] + [:div.open-bounties-filter-and-sort + [bounties-filters] + [bounties-sort]] + (if (empty? open-bounties) + [:div.view-no-data-container + [:p "No recent activity yet"]] + (into [:div.ui.items] + (for [bounty open-bounties] + [bounty-item bounty])))]) (defn bounties-page [] diff --git a/src/cljs/commiteth/db.cljs b/src/cljs/commiteth/db.cljs index 4a51dbf..e54bcd1 100644 --- a/src/cljs/commiteth/db.cljs +++ b/src/cljs/commiteth/db.cljs @@ -1,14 +1,19 @@ (ns commiteth.db) +(def bounty-sorting-types {::bounty-sorting-type|most-recent "Most recent" + ::bounty-sorting-type|lowest-value "Lowest value" + ::bounty-sorting-type|highest-value "Highest value" + ::bounty-sorting-type|owner "Owner"}) + (def default-db - {:page :bounties - :user nil - :repos-loading? false - :repos {} + {:page :bounties + :user nil + :repos-loading? false + :repos {} :activity-feed-loading? false :open-bounties-loading? false - :open-bounties [] - :owner-bounties {} - :top-hunters [] - :activity-feed [] - :bounties-order ::bounties-order|most-recent}) + :open-bounties [] + :owner-bounties {} + :top-hunters [] + :activity-feed [] + ::bounty-sorting-type ::bounty-sorting-type|most-recent}) diff --git a/src/cljs/commiteth/handlers.cljs b/src/cljs/commiteth/handlers.cljs index 528c116..b69f1ca 100644 --- a/src/cljs/commiteth/handlers.cljs +++ b/src/cljs/commiteth/handlers.cljs @@ -453,3 +453,8 @@ (fn [db [_]] (.removeEventListener js/window "click" close-dropdown) (assoc db :user-dropdown-open? false))) + +(reg-event-db + ::set-bounty-sorting-type + (fn [db [_ sorting-type]] + (assoc db ::db/bounty-sorting-type sorting-type))) diff --git a/src/cljs/commiteth/subscriptions.cljs b/src/cljs/commiteth/subscriptions.cljs index 9228ddc..c6d4340 100644 --- a/src/cljs/commiteth/subscriptions.cljs +++ b/src/cljs/commiteth/subscriptions.cljs @@ -1,5 +1,6 @@ (ns commiteth.subscriptions - (:require [re-frame.core :refer [reg-sub]])) + (:require [re-frame.core :refer [reg-sub]] + [commiteth.db :as db])) (reg-sub :db @@ -82,6 +83,6 @@ (:user-dropdown-open? db))) (reg-sub - :bounties-order + ::db/bounty-sorting-type (fn [db _] - (:bounties-order db))) + (::db/bounty-sorting-type db))) diff --git a/src/less/style.less b/src/less/style.less index 1c9eeef..e52f7fa 100644 --- a/src/less/style.less +++ b/src/less/style.less @@ -484,8 +484,7 @@ .open-bounties-sort-element-tooltip { position: absolute; right: 0; - //margin-top: 12px; - padding: 16px 24px; + //padding: 16px 0; min-width: 200px; border-radius: 8px; background-color: #1e3751; @@ -496,6 +495,15 @@ color: #ffffff; } + .open-bounties-sort-type { + padding: 19px 24px; + border-bottom: 1px solid rgba(255, 255, 255, 0.1); + } + + .open-bounties-sort-type:hover { + cursor: pointer; + } + .icon-forward-white-box { width: 24px; height: 24px;