mirror of
https://github.com/status-im/open-bounty.git
synced 2025-01-11 18:14:25 +00:00
Move selection behaviour and option list population to dropdown component
This commit is contained in:
parent
c5fdad5b8e
commit
a52f5f2b20
@ -10,19 +10,26 @@
|
||||
(merge props {:type "text"
|
||||
:value @val-ratom
|
||||
:on-change #(reset! val-ratom (-> % .-target .-value))})]))
|
||||
|
||||
(defn dropdown [props title val-ratom items]
|
||||
(fn []
|
||||
[:select.ui.basic.selection.dropdown
|
||||
(merge props {:on-change
|
||||
#(let [selected-value (-> % .-target .-value)]
|
||||
(when (not= selected-value title)
|
||||
(reset! val-ratom selected-value)))
|
||||
:default-value (if (contains? (set items) @val-ratom)
|
||||
@val-ratom
|
||||
title)})
|
||||
(conj (doall (for [item items]
|
||||
^{:key item} [:option {:value item} item]))
|
||||
^{:key title} [:option {:value title :disabled true} title])]))
|
||||
"If val-ratom is set, preselect it in the dropdown.
|
||||
Add value of val-ratom if it's missing from items list.
|
||||
Otherwise, prepend title as a disabled option"
|
||||
(let [items (cond-> items
|
||||
(and @val-ratom
|
||||
(not (contains? (set items) @val-ratom)))
|
||||
(conj @val-ratom)
|
||||
(not @val-ratom)
|
||||
(conj title))]
|
||||
(fn []
|
||||
[:select.ui.basic.selection.dropdown
|
||||
(merge props {:on-change
|
||||
#(reset! val-ratom (-> % .-target .-value))
|
||||
:default-value (or @val-ratom title)})
|
||||
(doall (for [item items]
|
||||
^{:key item} [:option {:value item
|
||||
:disabled (= item title)}
|
||||
item]))])))
|
||||
|
||||
(defn moment-timestamp [time]
|
||||
(let [now (.now js/Date.)
|
||||
|
@ -11,9 +11,8 @@
|
||||
(let [db (rf/subscribe [:db])
|
||||
user (rf/subscribe [:user])
|
||||
updating-address (rf/subscribe [:get-in [:updating-address]])
|
||||
address (-> @(rf/subscribe [:get-in [:user :address]])
|
||||
str/lower-case
|
||||
r/atom)]
|
||||
address (r/atom (some-> @(rf/subscribe [:get-in [:user :address]])
|
||||
str/lower-case))]
|
||||
(fn []
|
||||
(let [web3 (:web3 @db)
|
||||
web3-accounts (when web3
|
||||
|
Loading…
x
Reference in New Issue
Block a user