Address dropdown: move items list construction to invocation point

This commit is contained in:
Vitaliy Vlasov 2018-02-01 15:40:54 +02:00
parent 9e9d0f6d4d
commit 50036b10dd
2 changed files with 25 additions and 21 deletions

View File

@ -13,23 +13,16 @@
(defn dropdown [props title val-ratom items]
"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)))
(into [@val-ratom])
(not @val-ratom)
(into [title]))]
(fn []
[:select.ui.basic.selection.dropdown
(merge props {:on-change
#(reset! val-ratom (-> % .-target .-value))
:default-value (or @val-ratom title)})
(for [item items]
^{:key item} [:option {:value item
:disabled (= item title)}
item])])))
Otherwise, prepend title as a disabled option."
(fn []
[:select.ui.basic.selection.dropdown
(merge props {:on-change
#(reset! val-ratom (-> % .-target .-value))
:default-value (or @val-ratom title)})
(for [item items]
^{:key item} [:option {:value item
:disabled (= item title)}
item])]))
(defn moment-timestamp [time]
(let [now (.now js/Date.)

View File

@ -24,10 +24,21 @@
[:p "Insert your Ethereum address in hex format."]
[:div.field
(if-not (empty? web3-accounts)
[dropdown {:class "address-input"}
"Select address"
address
(map str/lower-case web3-accounts)]
; Add value of address if it's missing from items list.
; If address is empty, add title
(let [accounts (map str/lower-case web3-accounts)
addr @address
title "Select address"
items (cond->> accounts
(and addr
(not (contains? (set accounts) addr)))
(into [addr])
(not addr)
(into [title]))]
[dropdown {:class "address-input"}
title
address
items])
[:div.ui.input.address-input
[input address {:placeholder "0x0000000000000000000000000000000000000000"
:auto-complete "off"