updated qr flow

This commit is contained in:
Roman Volosovskyi 2016-06-02 17:39:26 +03:00
parent 485718d871
commit db46a3a3cb
6 changed files with 68 additions and 50 deletions

View File

@ -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))

View File

@ -27,7 +27,8 @@
[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
@ -45,7 +46,6 @@
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
@ -55,19 +55,15 @@
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)]]])
]]))

View File

@ -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 ""

View File

@ -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])))))

View File

@ -21,13 +21,12 @@
: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
@ -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}]]]])
])

View File

@ -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))