From 559f4f4212959474e16b9d035cd0b05af1904408 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Wed, 27 Dec 2017 21:04:32 +0300 Subject: [PATCH] 193 checkbox updated --- src/cljs/commiteth/common.cljs | 15 --------------- src/cljs/commiteth/update_address.cljs | 20 ++++++++++++-------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/cljs/commiteth/common.cljs b/src/cljs/commiteth/common.cljs index 6802845..9d302f0 100644 --- a/src/cljs/commiteth/common.cljs +++ b/src/cljs/commiteth/common.cljs @@ -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)) diff --git a/src/cljs/commiteth/update_address.cljs b/src/cljs/commiteth/update_address.cljs index 2bc7d81..e0153c8 100644 --- a/src/cljs/commiteth/update_address.cljs +++ b/src/cljs/commiteth/update_address.cljs @@ -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."]]]]))))