parent
18e6b80e18
commit
1d3a91c0ee
|
@ -112,12 +112,9 @@
|
||||||
(after save-contact)
|
(after save-contact)
|
||||||
add-new-contact)
|
add-new-contact)
|
||||||
|
|
||||||
(defn set-new-contact-from-qr [db [_ identifier]]
|
(defn set-new-contact-from-qr
|
||||||
(let [new-contact (:new-contact db)
|
[{:keys [new-contact] :as db} [_ _ qr-contact]]
|
||||||
qr-contact (get-in db [:qr-codes identifier])]
|
(println "WWUUUUUUTTT" qr-contact)
|
||||||
(-> db
|
(assoc db :new-contact (merge new-contact qr-contact)))
|
||||||
(assoc :new-contact (merge new-contact qr-contact))
|
|
||||||
(update-in db [:qr-codes] dissoc identifier))))
|
|
||||||
|
|
||||||
(register-handler :set-new-contact-from-qr
|
(register-handler :set-new-contact-from-qr set-new-contact-from-qr)
|
||||||
(-> set-new-contact-from-qr))
|
|
||||||
|
|
|
@ -27,47 +27,43 @@
|
||||||
[status-im.utils.logging :as log]))
|
[status-im.utils.logging :as log]))
|
||||||
|
|
||||||
(defn import-qr-button []
|
(defn import-qr-button []
|
||||||
[touchable-highlight {:on-press #(dispatch [:scan-qr-code :new-contact])}
|
[touchable-highlight
|
||||||
|
{:on-press #(dispatch [:scan-qr-code :new-contact :set-new-contact-from-qr])}
|
||||||
[view st/import-qr-button
|
[view st/import-qr-button
|
||||||
[view st/import-qr-button-content
|
[view st/import-qr-button-content
|
||||||
[icon {:name :qr-scanner
|
[icon {:name :qr-scanner
|
||||||
:style import-qr-icon}]
|
:style import-qr-icon}]
|
||||||
[text {:style st/import-qr-text} (label :t/import-qr)]]]])
|
[text {:style st/import-qr-text} (label :t/import-qr)]]]])
|
||||||
|
|
||||||
(defview contact-name-input [name]
|
(defview contact-name-input [name]
|
||||||
[]
|
[]
|
||||||
[text-input
|
[text-input
|
||||||
{:underlineColorAndroid color-purple
|
{:underlineColorAndroid color-purple
|
||||||
:style form-text-input
|
:style form-text-input
|
||||||
:autoFocus true
|
:autoFocus true
|
||||||
:placeholder (label :t/contact-name)
|
:placeholder (label :t/contact-name)
|
||||||
:onChangeText #(dispatch [:set-in [:new-contact :name] %])}
|
:onChangeText #(dispatch [:set-in [:new-contact :name] %])}
|
||||||
name])
|
name])
|
||||||
|
|
||||||
(defview contact-address-input [address]
|
(defview contact-address-input [address]
|
||||||
[]
|
[text-input
|
||||||
[text-input
|
{:underlineColorAndroid color-purple
|
||||||
{:underlineColorAndroid color-purple
|
:style form-text-input
|
||||||
:style form-text-input
|
:autoFocus true
|
||||||
:autoFocus true
|
:placeholder (label :t/contact-address)
|
||||||
:placeholder (label :t/contact-address)
|
:onChangeText #(dispatch [:set-in [:new-contact :address] %])}
|
||||||
:onChangeText #(dispatch [:set-in [:new-contact :address] %])}
|
address])
|
||||||
address])
|
|
||||||
|
|
||||||
(defview new-contact []
|
(defview new-contact []
|
||||||
[{:keys [name address whisper-identity phone-number] :as new-contact} [:get :new-contact]
|
[{:keys [name address whisper-identity phone-number] :as new-contact} [:get :new-contact]]
|
||||||
qr-contact [:get-in [:qr-codes :new-contact]]]
|
|
||||||
(let [_ (log/debug qr-contact)
|
|
||||||
_ (when qr-contact (dispatch [:set-new-contact-from-qr :new-contact]))]
|
|
||||||
[drawer-view
|
[drawer-view
|
||||||
[view st/contact-form-container
|
[view st/contact-form-container
|
||||||
[toolbar {:title (label :t/new-contact)
|
[toolbar {:title (label :t/new-contact)
|
||||||
:background-color toolbar-background2
|
:background-color toolbar-background2
|
||||||
:action {:image {:source {:uri :icon_add_gray}
|
:action {:image {:source {:uri :icon_add_gray}
|
||||||
:style search-icon}
|
:style search-icon}
|
||||||
:handler (fn [] (dispatch [:add-new-contact new-contact]))}}]
|
:handler #(dispatch [:add-new-contact new-contact])}}]
|
||||||
[import-qr-button]
|
[import-qr-button]
|
||||||
[contact-name-input name]
|
[contact-name-input name]
|
||||||
[contact-address-input address]
|
[contact-address-input address]
|
||||||
[text (str "Whisper identity: " whisper-identity)]
|
[text (str "Whisper identity: " whisper-identity)]]])
|
||||||
]]))
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
:email "myemail@gmail.com"
|
:email "myemail@gmail.com"
|
||||||
:status "Hi, this is my status"
|
:status "Hi, this is my status"
|
||||||
:current-tag nil
|
:current-tag nil
|
||||||
:qr-codes {:identifier nil}
|
:qr-codes {}
|
||||||
:new-contact {:name ""
|
:new-contact {:name ""
|
||||||
:address ""
|
:address ""
|
||||||
:whisper-identity ""
|
:whisper-identity ""
|
||||||
|
|
|
@ -1,12 +1,39 @@
|
||||||
(ns status-im.qr-scanner.handlers
|
(ns status-im.qr-scanner.handlers
|
||||||
(:require [re-frame.core :refer [register-handler after dispatch debug enrich]]))
|
(:require [re-frame.core :refer [register-handler after dispatch debug enrich]]
|
||||||
|
[status-im.navigation.handlers :as nav]
|
||||||
|
[status-im.utils.handlers :as u]))
|
||||||
|
|
||||||
(defn set-current-identifier [db [_ identifier]]
|
(defmethod nav/preload-data! :qr-scanner
|
||||||
(assoc-in db [:qr-codes :identifier] identifier))
|
[db [_ _ identifier]]
|
||||||
|
(assoc db :current-qr-context identifier))
|
||||||
|
|
||||||
|
(defn set-current-identifier [db [_ identifier handler]]
|
||||||
|
(assoc-in db [:qr-codes identifier] handler))
|
||||||
|
|
||||||
|
(defn navigate-to-scanner
|
||||||
|
[_ [_ identifier]]
|
||||||
|
(dispatch [:navigate-to :qr-scanner identifier]))
|
||||||
|
|
||||||
(register-handler :scan-qr-code
|
(register-handler :scan-qr-code
|
||||||
(-> set-current-identifier
|
(after navigate-to-scanner)
|
||||||
((after (fn [_ _] (dispatch [:navigate-to :qr-scanner]))))))
|
set-current-identifier)
|
||||||
|
|
||||||
(register-handler :clear-qr-code [db [_ identifier]]
|
(register-handler :clear-qr-code
|
||||||
(update-in db [:qr-codes] dissoc identifier))
|
(fn [db [_ identifier]]
|
||||||
|
(update db :qr-codes dissoc identifier)))
|
||||||
|
|
||||||
|
(defn handle-qr-request
|
||||||
|
[db [_ context data]]
|
||||||
|
(let [handler (get-in db [:qr-codes context])]
|
||||||
|
(println handler context data)
|
||||||
|
(dispatch [handler context data])))
|
||||||
|
|
||||||
|
(defn clear-qr-request [db [_ context]]
|
||||||
|
(-> db
|
||||||
|
(update :qr-codes dissoc context)
|
||||||
|
(dissoc :current-qr-context)))
|
||||||
|
|
||||||
|
(register-handler :set-qr-code
|
||||||
|
(-> (u/side-effect! handle-qr-request)
|
||||||
|
((enrich clear-qr-request))
|
||||||
|
((after #(dispatch [:navigate-back])))))
|
||||||
|
|
|
@ -21,14 +21,13 @@
|
||||||
:background-color toolbar-background2}])
|
:background-color toolbar-background2}])
|
||||||
|
|
||||||
(defview qr-scanner []
|
(defview qr-scanner []
|
||||||
[identifier [:get-in [:qr-codes :identifier]]]
|
[identifier [:get :current-qr-context]]
|
||||||
[view st/barcode-scanner-container
|
[view st/barcode-scanner-container
|
||||||
[qr-scanner-toolbar]
|
[qr-scanner-toolbar]
|
||||||
[camera {:onBarCodeRead (fn [data]
|
[camera {;:on-bar-code-read #(js/alert "ok")
|
||||||
(let [data (json->clj (.-data data))]
|
:onBarCodeRead #(let [data (json->clj (.-data %))]
|
||||||
(dispatch [:set-in [:qr-codes (or identifier :current)] data])
|
(dispatch [:set-qr-code identifier data]))
|
||||||
(dispatch [:navigate-back])))
|
:style st/barcode-scanner}]
|
||||||
:style st/barcode-scanner}]
|
|
||||||
[view st/rectangle-container
|
[view st/rectangle-container
|
||||||
[view st/rectangle
|
[view st/rectangle
|
||||||
[image {:source {:uri :corner_left_top}
|
[image {:source {:uri :corner_left_top}
|
||||||
|
@ -38,5 +37,4 @@
|
||||||
[image {:source {:uri :corner_right_bottom}
|
[image {:source {:uri :corner_right_bottom}
|
||||||
:style st/corner-right-bottom}]
|
:style st/corner-right-bottom}]
|
||||||
[image {:source {:uri :corner_left_bottom}
|
[image {:source {:uri :corner_left_bottom}
|
||||||
:style st/corner-left-bottom}]]]
|
:style st/corner-left-bottom}]]]])
|
||||||
])
|
|
||||||
|
|
|
@ -12,4 +12,4 @@
|
||||||
(.stringify js/JSON (clj->js data)))
|
(.stringify js/JSON (clj->js data)))
|
||||||
|
|
||||||
(defn json->clj [data]
|
(defn json->clj [data]
|
||||||
(js->clj (.parse js/JSON data)))
|
(js->clj (.parse js/JSON data) :keywordize-keys true))
|
||||||
|
|
Loading…
Reference in New Issue