193 checkbox updated

This commit is contained in:
Ivan Grishaev 2017-12-27 21:04:32 +03:00
parent fea8d4f0b5
commit 559f4f4212
2 changed files with 12 additions and 23 deletions

View File

@ -10,21 +10,6 @@
:value @val-ratom
:on-change #(reset! val-ratom (-> % .-target .-value))})]))
(defn checkbox
"Common checkbox widget. Takes a boolean value wrapped into an atom
and updates its state when clicking in it. An additional `opt` map
is to override its attributes (class, id, etc)."
[val-atom & [opt]]
[:input
(merge
{:type :checkbox
:checked @val-atom
:on-change
(fn [e]
(let [value (-> e .-target .-checked)]
(reset! val-atom value)))}
opt)])
(defn dropdown [props title val-ratom items]
(fn []
(if (= 1 (count items))

View File

@ -1,6 +1,6 @@
(ns commiteth.update-address
(:require [re-frame.core :as rf]
[commiteth.common :refer [input dropdown checkbox]]
[commiteth.common :refer [input dropdown]]
[reagent.core :as r]
[reagent.crypt :as crypt]
[cljs-web3.eth :as web3-eth]))
@ -10,12 +10,7 @@
user (rf/subscribe [:user])
updating-address (rf/subscribe [:get-in [:updating-address]])
address (r/atom @(rf/subscribe [:get-in [:user :address]]))
hidden (r/atom @(rf/subscribe [:get-in [:user :is_hidden]]))]
(add-watch hidden
:default
(fn [_ _ _ new-val]
(rf/dispatch [:mark-user-hidden (:id @user) new-val])))
hidden (rf/subscribe [:get-in [:user :is_hidden]])]
(fn []
(let [web3 (:web3 @db)
@ -50,5 +45,14 @@
[:h3 "Settings"]
[:div
[checkbox hidden {:id :input-hidden}]
[:input
{:type :checkbox
:id :input-hidden
:checked @hidden
:on-change
(fn [e]
(let [value (-> e .-target .-checked)]
(rf/dispatch [:mark-user-hidden (:id @user) value])))}]
[:label {:for :input-hidden} "Disguise myself from the top hunters and activity lists."]]]]))))