abstracting filter type category
This commit is contained in:
parent
561232d6e2
commit
fdec3ad56b
|
@ -47,10 +47,6 @@
|
||||||
[:div.ui.tiny.circular.image
|
[:div.ui.tiny.circular.image
|
||||||
[:img {:src avatar-url}]]]]))
|
[:img {:src avatar-url}]]]]))
|
||||||
|
|
||||||
(defn bounties-filter-tooltip [content]
|
|
||||||
[:div.open-bounties-filter-element-tooltip
|
|
||||||
content])
|
|
||||||
|
|
||||||
(defn bounties-filter-tooltip-value-input [label tooltip-open? opts]
|
(defn bounties-filter-tooltip-value-input [label tooltip-open? opts]
|
||||||
[:div.open-bounties-filter-element-tooltip-value-input-container
|
[:div.open-bounties-filter-element-tooltip-value-input-container
|
||||||
[:div.:input.open-bounties-filter-element-tooltip-value-input-label
|
[:div.:input.open-bounties-filter-element-tooltip-value-input-label
|
||||||
|
@ -65,15 +61,15 @@
|
||||||
#(-> % .-target .-value int f))
|
#(-> % .-target .-value int f))
|
||||||
:on-focus #(reset! tooltip-open? true)}]])
|
:on-focus #(reset! tooltip-open? true)}]])
|
||||||
|
|
||||||
(defn bounties-filter-tooltip-value [current-filter-value tooltip-open?]
|
(defn bounties-filter-tooltip-category-range [filter-type filter-type-def current-filter-value tooltip-open?]
|
||||||
(let [default-min 0
|
(let [default-min (::ui-model/bounty-filter-type.min-val filter-type-def)
|
||||||
default-max 1000
|
default-max (::ui-model/bounty-filter-type.max-val filter-type-def)
|
||||||
common-range-opts {:min default-min :max default-max}
|
common-range-opts {:min default-min :max default-max}
|
||||||
current-min (or (first current-filter-value) default-min)
|
current-min (or (first current-filter-value) default-min)
|
||||||
current-max (or (second current-filter-value) default-max)
|
current-max (or (second current-filter-value) default-max)
|
||||||
on-change-fn (fn [min-val max-val]
|
on-change-fn (fn [min-val max-val]
|
||||||
(rf/dispatch [::handlers/set-open-bounty-filter-type
|
(rf/dispatch [::handlers/set-open-bounty-filter-type
|
||||||
::ui-model/bounty-filter-type|value
|
filter-type
|
||||||
[(min min-val default-max)
|
[(min min-val default-max)
|
||||||
(max max-val default-min)]]))
|
(max max-val default-min)]]))
|
||||||
on-min-change-fn (fn [new-min]
|
on-min-change-fn (fn [new-min]
|
||||||
|
@ -91,80 +87,66 @@
|
||||||
{:current-val current-max
|
{:current-val current-max
|
||||||
:on-change-val on-max-change-fn})]]))
|
:on-change-val on-max-change-fn})]]))
|
||||||
|
|
||||||
(defn bounties-filter-tooltip-currency [current-filter-value tooltip-open?]
|
(defn bounties-filter-tooltip-category-single-static-option
|
||||||
(let [currencies (rf/subscribe [::subs/open-bounties-currencies])]
|
[filter-type filter-type-def current-filter-value tooltip-open?]
|
||||||
[:div.open-bounties-filter-list
|
|
||||||
(for [currency @currencies]
|
|
||||||
(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
|
|
||||||
::ui-model/bounty-filter-type|currency
|
|
||||||
(cond
|
|
||||||
(and active? (= #{currency} current-filter-value)) nil
|
|
||||||
active? (disj current-filter-value currency)
|
|
||||||
:else (into #{currency} current-filter-value))])
|
|
||||||
:tab-index 0
|
|
||||||
:on-focus #(do (.stopPropagation %) (reset! tooltip-open? true))}
|
|
||||||
[:input
|
|
||||||
{:type "checkbox"
|
|
||||||
:checked active?
|
|
||||||
:on-focus #(reset! tooltip-open? true)}]
|
|
||||||
[:div.text currency]]]))]))
|
|
||||||
|
|
||||||
(defn bounties-filter-tooltip-date [current-filter-value tooltip-open?]
|
|
||||||
[:div.open-bounties-filter-list
|
[:div.open-bounties-filter-list
|
||||||
(for [[option-type option-text] ui-model/bounty-filter-type-date-options-def]
|
(for [[option-type option-text] (::ui-model/bounty-filter-type.options filter-type-def)]
|
||||||
^{:key (str option-type)}
|
^{:key (str option-type)}
|
||||||
[:div.open-bounties-filter-list-option
|
[:div.open-bounties-filter-list-option
|
||||||
(merge {:on-click #(do (rf/dispatch [::handlers/set-open-bounty-filter-type
|
(merge {:on-click #(do (rf/dispatch [::handlers/set-open-bounty-filter-type
|
||||||
::ui-model/bounty-filter-type|date
|
filter-type
|
||||||
option-type])
|
option-type])
|
||||||
(reset! tooltip-open? false))}
|
(reset! tooltip-open? false))}
|
||||||
(when (= option-type current-filter-value)
|
(when (= option-type current-filter-value)
|
||||||
{:class "active"}))
|
{:class "active"}))
|
||||||
option-text])])
|
option-text])])
|
||||||
|
|
||||||
(defn bounties-filter-tooltip-owner [current-filter-value tooltip-open?]
|
(defn bounties-filter-tooltip-category-multiple-dynamic-options
|
||||||
(let [owners (rf/subscribe [::subs/open-bounties-owners])]
|
[filter-type filter-type-def current-filter-value tooltip-open?]
|
||||||
|
(let [options (rf/subscribe [(::ui-model/bounty-filter-type.re-frame-subscription-key-for-options filter-type-def)])]
|
||||||
[:div.open-bounties-filter-list
|
[:div.open-bounties-filter-list
|
||||||
(for [owner @owners]
|
(for [option @options]
|
||||||
(let [active? (boolean (and current-filter-value (current-filter-value owner)))]
|
(let [active? (boolean (and current-filter-value (current-filter-value option)))]
|
||||||
^{:key (str owner)}
|
^{:key (str option)}
|
||||||
[:div.open-bounties-filter-list-option-checkbox
|
[:div.open-bounties-filter-list-option-checkbox
|
||||||
[:label
|
[:label
|
||||||
{:on-click #(rf/dispatch [::handlers/set-open-bounty-filter-type
|
{:on-click #(rf/dispatch [::handlers/set-open-bounty-filter-type
|
||||||
::ui-model/bounty-filter-type|owner
|
filter-type
|
||||||
(cond
|
(cond
|
||||||
(and active? (= #{owner} current-filter-value)) nil
|
(and active? (= #{option} current-filter-value)) nil
|
||||||
active? (disj current-filter-value owner)
|
active? (disj current-filter-value option)
|
||||||
:else (into #{owner} current-filter-value))])
|
:else (into #{option} current-filter-value))])
|
||||||
:tab-index 0
|
:tab-index 0
|
||||||
:on-focus #(do (.stopPropagation %) (reset! tooltip-open? true))}
|
:on-focus #(do (.stopPropagation %) (reset! tooltip-open? true))}
|
||||||
[:input
|
[:input
|
||||||
{:type "checkbox"
|
{:type "checkbox"
|
||||||
:checked active?
|
:checked active?
|
||||||
:on-focus #(reset! tooltip-open? true)}]
|
:on-focus #(reset! tooltip-open? true)}]
|
||||||
[:div.text owner]]]))]))
|
[:div.text option]]]))]))
|
||||||
|
|
||||||
(defn- tooltip-view-for-filter-type [filter-type]
|
(defn bounties-filter-tooltip [filter-type filter-type-def current-filter-val tooltip-open?]
|
||||||
(condp = filter-type
|
[:div.open-bounties-filter-element-tooltip
|
||||||
::ui-model/bounty-filter-type|value bounties-filter-tooltip-value
|
(let [compo (condp = (::ui-model/bounty-filter-type.category filter-type-def)
|
||||||
::ui-model/bounty-filter-type|currency bounties-filter-tooltip-currency
|
::ui-model/bounty-filter-type-category|single-static-option
|
||||||
::ui-model/bounty-filter-type|date bounties-filter-tooltip-date
|
bounties-filter-tooltip-category-single-static-option
|
||||||
::ui-model/bounty-filter-type|owner bounties-filter-tooltip-owner))
|
|
||||||
|
::ui-model/bounty-filter-type-category|multiple-dynamic-options
|
||||||
|
bounties-filter-tooltip-category-multiple-dynamic-options
|
||||||
|
|
||||||
|
::ui-model/bounty-filter-type-category|range
|
||||||
|
bounties-filter-tooltip-category-range)]
|
||||||
|
(compo filter-type filter-type-def current-filter-val tooltip-open?))])
|
||||||
|
|
||||||
(defn bounty-filter-view [filter-type current-filter-value]
|
(defn bounty-filter-view [filter-type current-filter-value]
|
||||||
(let [open? (r/atom false)]
|
(let [tooltip-open? (r/atom false)]
|
||||||
(fn [filter-type current-filter-value]
|
(fn [filter-type current-filter-value]
|
||||||
[:div.open-bounties-filter-element-container
|
[:div.open-bounties-filter-element-container
|
||||||
{:tab-index 0
|
{:tab-index 0
|
||||||
:on-focus #(reset! open? true)
|
:on-focus #(reset! tooltip-open? true)
|
||||||
:on-blur #(reset! open? false)}
|
:on-blur #(reset! tooltip-open? false)}
|
||||||
[:div.open-bounties-filter-element
|
[:div.open-bounties-filter-element
|
||||||
{:on-mouse-down #(swap! open? not)
|
{:on-mouse-down #(swap! tooltip-open? not)
|
||||||
:class (when (or current-filter-value @open?)
|
:class (when (or current-filter-value @tooltip-open?)
|
||||||
"open-bounties-filter-element-active")}
|
"open-bounties-filter-element-active")}
|
||||||
[:div.text
|
[:div.text
|
||||||
(if current-filter-value
|
(if current-filter-value
|
||||||
|
@ -179,10 +161,13 @@
|
||||||
:on-mouse-down (fn [e]
|
:on-mouse-down (fn [e]
|
||||||
(.stopPropagation e)
|
(.stopPropagation e)
|
||||||
(rf/dispatch [::handlers/set-open-bounty-filter-type filter-type nil])
|
(rf/dispatch [::handlers/set-open-bounty-filter-type filter-type nil])
|
||||||
(reset! open? false))}]])]
|
(reset! tooltip-open? false))}]])]
|
||||||
(when @open?
|
(when @tooltip-open?
|
||||||
[bounties-filter-tooltip
|
[bounties-filter-tooltip
|
||||||
[(tooltip-view-for-filter-type filter-type) current-filter-value open?]])])))
|
filter-type
|
||||||
|
(ui-model/bounty-filter-types-def filter-type)
|
||||||
|
current-filter-value
|
||||||
|
tooltip-open?])])))
|
||||||
|
|
||||||
(defn bounty-filters-view []
|
(defn bounty-filters-view []
|
||||||
(let [current-filters (rf/subscribe [::subs/open-bounties-filters])]
|
(let [current-filters (rf/subscribe [::subs/open-bounties-filters])]
|
||||||
|
|
|
@ -38,19 +38,32 @@
|
||||||
|
|
||||||
;;;; bounty filter types
|
;;;; bounty filter types
|
||||||
|
|
||||||
|
(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"
|
||||||
|
::bounty-filter-type-date-option|last-3-months "Last 3 months"})
|
||||||
|
|
||||||
|
(def bounty-filter-type-date-options (keys bounty-filter-type-date-options-def))
|
||||||
|
|
||||||
(def bounty-filter-types-def
|
(def bounty-filter-types-def
|
||||||
{::bounty-filter-type|value {::bounty-filter-type.name "Value"
|
{::bounty-filter-type|value {::bounty-filter-type.name "Value"
|
||||||
|
::bounty-filter-type.category ::bounty-filter-type-category|range
|
||||||
|
::bounty-filter-type.min-val 0
|
||||||
|
::bounty-filter-type.max-val 1000
|
||||||
::bounty-filter-type.predicate (fn [filter-value bounty]
|
::bounty-filter-type.predicate (fn [filter-value bounty]
|
||||||
(let [min-val (first filter-value)
|
(let [min-val (first filter-value)
|
||||||
max-val (second filter-value)]
|
max-val (second filter-value)]
|
||||||
(<= min-val (:value-usd bounty) max-val)))}
|
(<= min-val (:value-usd bounty) max-val)))}
|
||||||
::bounty-filter-type|currency {::bounty-filter-type.name "Currency"
|
::bounty-filter-type|currency {::bounty-filter-type.name "Currency"
|
||||||
::bounty-filter-type.predicate (fn [filter-value bounty]
|
::bounty-filter-type.category ::bounty-filter-type-category|multiple-dynamic-options
|
||||||
(and (or (not-any? #{"ETH"} filter-value)
|
::bounty-filter-type.re-frame-subscription-key-for-options :commiteth.subscriptions/open-bounties-currencies
|
||||||
(< 0 (:balance-eth bounty)))
|
::bounty-filter-type.predicate (fn [filter-value bounty]
|
||||||
(set/subset? (->> filter-value (remove #{"ETH"}) set)
|
(and (or (not-any? #{"ETH"} filter-value)
|
||||||
(-> bounty :tokens keys set))))}
|
(< 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|date {::bounty-filter-type.name "Date"
|
||||||
|
::bounty-filter-type.category ::bounty-filter-type-category|single-static-option
|
||||||
|
::bounty-filter-type.options bounty-filter-type-date-options-def
|
||||||
::bounty-filter-type.predicate (fn [filter-value bounty]
|
::bounty-filter-type.predicate (fn [filter-value bounty]
|
||||||
(when-let [created-at-inst (:created-at bounty)]
|
(when-let [created-at-inst (:created-at bounty)]
|
||||||
(let [created-at-date (-> created-at-inst inst-ms t-coerce/from-long)
|
(let [created-at-date (-> created-at-inst inst-ms t-coerce/from-long)
|
||||||
|
@ -60,23 +73,19 @@
|
||||||
::bounty-filter-type-date-option|last-3-months (t/minus (t/now) (t/months 3)))
|
::bounty-filter-type-date-option|last-3-months (t/minus (t/now) (t/months 3)))
|
||||||
interval (t/interval filter-from (t/now))]
|
interval (t/interval filter-from (t/now))]
|
||||||
(t/within? interval created-at-date))))}
|
(t/within? interval created-at-date))))}
|
||||||
::bounty-filter-type|owner {::bounty-filter-type.name "Owner"
|
::bounty-filter-type|owner {::bounty-filter-type.name "Owner"
|
||||||
::bounty-filter-type.predicate (fn [filter-value bounty]
|
::bounty-filter-type.category ::bounty-filter-type-category|multiple-dynamic-options
|
||||||
(->> filter-value
|
::bounty-filter-type.re-frame-subscription-key-for-options :commiteth.subscriptions/open-bounties-owners
|
||||||
(some #{(:repo-owner bounty)})
|
::bounty-filter-type.predicate (fn [filter-value bounty]
|
||||||
boolean))}})
|
(->> filter-value
|
||||||
|
(some #{(:repo-owner bounty)})
|
||||||
|
boolean))}})
|
||||||
|
|
||||||
(def bounty-filter-types (keys bounty-filter-types-def))
|
(def bounty-filter-types (keys bounty-filter-types-def))
|
||||||
|
|
||||||
(defn bounty-filter-type->name [filter-type]
|
(defn bounty-filter-type->name [filter-type]
|
||||||
(-> bounty-filter-types-def (get filter-type) ::bounty-filter-type.name))
|
(-> 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"
|
|
||||||
::bounty-filter-type-date-option|last-3-months "Last 3 months"})
|
|
||||||
|
|
||||||
(def bounty-filter-type-date-options (keys bounty-filter-type-date-options-def))
|
|
||||||
|
|
||||||
(defn bounty-filter-type-date-option->name [option]
|
(defn bounty-filter-type-date-option->name [option]
|
||||||
(bounty-filter-type-date-options-def option))
|
(bounty-filter-type-date-options-def option))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue