fix ui checkbox checked and start filtering

This commit is contained in:
pablodip 2018-01-22 12:21:04 +01:00
parent 09cd84a89b
commit d937bf361d
3 changed files with 45 additions and 18 deletions

View File

@ -95,7 +95,8 @@
(let [currencies (rf/subscribe [::subs/open-bounties-currencies])]
[:div.open-bounties-filter-list
(for [currency @currencies]
(let [active? (and current-filter-value (current-filter-value currency))]
(let [active? (boolean (and current-filter-value (current-filter-value currency)))]
^{:key (str currency)}
[:div.open-bounties-filter-list-option-checkbox
[:label
{:on-click #(rf/dispatch [::handlers/set-open-bounty-filter-type
@ -106,6 +107,7 @@
:else (into #{currency} current-filter-value))])}
[:input
{:type "checkbox"
:checked active?
:on-focus #(reset! tooltip-open? true)}]
[:div.text currency]]]))]))
@ -126,7 +128,8 @@
(let [owners (rf/subscribe [::subs/open-bounties-owners])]
[:div.open-bounties-filter-list
(for [owner @owners]
(let [active? (and current-filter-value (current-filter-value owner))]
(let [active? (boolean (and current-filter-value (current-filter-value owner)))]
^{:key (str owner)}
[:div.open-bounties-filter-list-option-checkbox
[:label
{:on-click #(rf/dispatch [::handlers/set-open-bounty-filter-type
@ -137,8 +140,8 @@
:else (into #{owner} current-filter-value))])}
[:input
{:type "checkbox"
:on-focus #(reset! tooltip-open? true)
:checked (when active? "checked")}]
:checked active?
:on-focus #(reset! tooltip-open? true)}]
[:div.text owner]]]))]))
(defn- tooltip-view-for-filter-type [filter-type]

View File

@ -107,7 +107,7 @@
(fn [open-bounties _]
(let [token-ids (->> open-bounties
(map :tokens)
(map keys)
(mapcat keys)
(filter identity)
set)]
(into #{"ETH"} token-ids))))
@ -115,9 +115,9 @@
(reg-sub
::filtered-and-sorted-open-bounties
:<- [:open-bounties]
:<- [::open-bounties-filters]
:<- [::open-bounties-sorting-type]
(fn [[open-bounties sorting-type] _]
(println "RAW" open-bounties)
(fn [[open-bounties filters sorting-type] _]
(cond->> open-bounties
sorting-type (ui-model/sort-bounties-by-sorting-type sorting-type)
)))
filters (ui-model/filter-bounties filters)
sorting-type (ui-model/sort-bounties-by-sorting-type sorting-type))))

View File

@ -1,4 +1,5 @@
(ns commiteth.ui-model)
(ns commiteth.ui-model
(:require [clojure.set :as set]))
;;;; bounty sorting types
@ -24,9 +25,9 @@
(-> 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)
(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)]
@ -34,15 +35,27 @@
;;;; bounty filter types
(def bounty-filter-types-def {::bounty-filter-type|value "Value"
::bounty-filter-type|currency "Currency"
::bounty-filter-type|date "Date"
::bounty-filter-type|owner "Owner"})
(def bounty-filter-types-def
{::bounty-filter-type|value {::bounty-filter-type.name "Value"
::bounty-filter-type.predicate (fn [filter-value bounty]
true)}
::bounty-filter-type|currency {::bounty-filter-type.name "Currency"
::bounty-filter-type.predicate (fn [filter-value bounty]
(and (or (not-any? #{"ETH"} filter-value)
(< 0 (:balance-eth bounty)))
(set/subset? (->> filter-value (remove #{"ETH"}) set)
(-> bounty :tokens keys set))))}
::bounty-filter-type|date {::bounty-filter-type.name "Date"
::bounty-filter-type.predicate (fn [filter-value bounty]
true)}
::bounty-filter-type|owner {::bounty-filter-type.name "Owner"
::bounty-filter-type.predicate (fn [filter-value bounty]
true)}})
(def bounty-filter-types (keys bounty-filter-types-def))
(defn bounty-filter-type->name [filter-type]
(bounty-filter-types-def filter-type))
(-> bounty-filter-types-def (get filter-type) ::bounty-filter-type.name))
(def bounty-filter-type-date-options-def {::bounty-filter-type-date-option|last-week "Last week"
::bounty-filter-type-date-option|last-month "Last month"
@ -67,3 +80,14 @@
:else
(str filter-type " with val " filter-value)))
(defn filter-bounties [filters-by-type bounties]
(let [filter-preds (->> filters-by-type
(remove #(nil? (val %)))
(map (fn [[filter-type filter-value]]
(let [pred (-> bounty-filter-types-def (get filter-type) ::bounty-filter-type.predicate)]
(partial pred filter-value)))))
filters-pred (fn [bounty]
(every? #(% bounty) filter-preds))]
(->> bounties
(filter filters-pred))))