sorting behaviour

This commit is contained in:
pablodip 2018-01-21 10:27:32 +01:00
parent d470b3aea3
commit 09cd84a89b
4 changed files with 56 additions and 19 deletions

View File

@ -155,7 +155,8 @@
:value_usd :value-usd
:claim_count :claim-count
:balance_eth :balance-eth
:user_has_address :user-has-address}]
:user_has_address :user-has-address
:created_at :created-at}]
(map #(-> %
(rename-keys renames)
(update :value-usd usd-decimal->str)

View File

@ -196,19 +196,19 @@
:on-blur #(reset! open? false)}
[:div.open-bounties-sort-element
{:on-click #(swap! open? not)}
(ui-model/bounty-sorting-types-def @current-sorting)
(ui-model/bounty-sorting-type->name @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] ui-model/bounty-sorting-types-def]
(for [sorting-type (keys ui-model/bounty-sorting-types-def)]
^{:key (str sorting-type)}
[:div.open-bounties-sort-type
{:on-click #(do
(reset! open? false)
(rf/dispatch [::handlers/set-open-bounties-sorting-type sorting-type]))}
sorting-name])])]))))
(ui-model/bounty-sorting-type->name sorting-type)])])]))))
(defn bounties-list [open-bounties]
[:div.ui.container.open-bounties-container
@ -225,7 +225,7 @@
(defn bounties-page []
(let [open-bounties (rf/subscribe [:open-bounties])
(let [open-bounties (rf/subscribe [::subs/filtered-and-sorted-open-bounties])
open-bounties-loading? (rf/subscribe [:get-in [:open-bounties-loading?]])]
(fn []
(if @open-bounties-loading?

View File

@ -1,10 +1,11 @@
(ns commiteth.subscriptions
(:require [re-frame.core :refer [reg-sub]]
[commiteth.db :as db]))
[commiteth.db :as db]
[commiteth.ui-model :as ui-model]))
(reg-sub
:db
(fn [db _] db))
:db
(fn [db _] db))
(reg-sub
:page
@ -68,17 +69,17 @@
(get-in db path)))
(reg-sub
:usage-metrics
(fn [db _]
(:usage-metrics db)))
:usage-metrics
(fn [db _]
(:usage-metrics db)))
(reg-sub
:metrics-loading?
(fn [db _]
(:metrics-loading? db)))
:metrics-loading?
(fn [db _]
(:metrics-loading? db)))
(reg-sub
:user-dropdown-open?
:user-dropdown-open?
(fn [db _]
(:user-dropdown-open? db)))
@ -110,3 +111,13 @@
(filter identity)
set)]
(into #{"ETH"} token-ids))))
(reg-sub
::filtered-and-sorted-open-bounties
:<- [:open-bounties]
:<- [::open-bounties-sorting-type]
(fn [[open-bounties sorting-type] _]
(println "RAW" open-bounties)
(cond->> open-bounties
sorting-type (ui-model/sort-bounties-by-sorting-type sorting-type)
)))

View File

@ -2,10 +2,35 @@
;;;; bounty sorting types
(def bounty-sorting-types-def {::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 bounty-sorting-types-def
{::bounty-sorting-type|most-recent {::bounty-sorting-type.name "Most recent"
::bounty-sorting-type.sort-key-fn (fn [bounty]
(:created-at bounty))
::bounty-sorting-type.sort-comparator-fn compare}
::bounty-sorting-type|lowest-value {::bounty-sorting-type.name "Lowest value"
::bounty-sorting-type.sort-key-fn (fn [bounty]
(:value-usd bounty))
::bounty-sorting-type.sort-comparator-fn compare}
::bounty-sorting-type|highest-value {::bounty-sorting-type.name "Highest value"
::bounty-sorting-type.sort-key-fn (fn [bounty]
(:value-usd bounty))
::bounty-sorting-type.sort-comparator-fn (comp - compare)}
::bounty-sorting-type|owner {::bounty-sorting-type.name "Owner"
::bounty-sorting-type.sort-key-fn (fn [bounty]
(:repo-owner bounty))
::bounty-sorting-type.sort-comparator-fn compare}})
(defn bounty-sorting-type->name [sorting-type]
(-> bounty-sorting-types-def (get sorting-type) ::bounty-sorting-type.name))
(defn sort-bounties-by-sorting-type [sorting-type bounties]
(let [keyfn (-> bounty-sorting-types-def
sorting-type
::bounty-sorting-type.sort-key-fn)
comparator (-> bounty-sorting-types-def
sorting-type
::bounty-sorting-type.sort-comparator-fn)]
(sort-by keyfn comparator bounties)))
;;;; bounty filter types