mirror of
https://github.com/status-im/open-bounty.git
synced 2025-02-27 00:20:46 +00:00
sorting behaviour
This commit is contained in:
parent
d470b3aea3
commit
09cd84a89b
@ -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)
|
||||
|
@ -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?
|
||||
|
@ -1,6 +1,7 @@
|
||||
(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
|
||||
@ -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)
|
||||
)))
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user