parent
b9973cee6d
commit
8f37885e18
|
@ -160,6 +160,18 @@ status.response({
|
|||
event: "save-password",
|
||||
params: [params.value]
|
||||
};
|
||||
},
|
||||
preview: function (params) {
|
||||
return status.components.text(
|
||||
{
|
||||
style: {
|
||||
marginTop: 5,
|
||||
marginHorizontal: 0,
|
||||
fontSize: 14,
|
||||
fontFamily: "font",
|
||||
color: "black"
|
||||
}
|
||||
}, "*****");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ Command.prototype.create = function (com) {
|
|||
this.color = com.color;
|
||||
this.icon = com.icon;
|
||||
this.params = com.params || [];
|
||||
this.preview = com.preview;
|
||||
this.addToCatalog();
|
||||
|
||||
return this;
|
||||
|
|
|
@ -45,8 +45,8 @@
|
|||
(defn invoke-suggestions-handler!
|
||||
[{:keys [current-chat-id] :as db} _]
|
||||
(let [commands (get-in db [:chats current-chat-id :commands])
|
||||
{:keys [command content]} (get-in db [:chats current-chat-id :command-input])]
|
||||
(let [path [(if (commands command) :commands :responses)
|
||||
{:keys [command content]} (get-in db [:chats current-chat-id :command-input])
|
||||
path [(if (commands command) :commands :responses)
|
||||
(:name command)
|
||||
:params
|
||||
0
|
||||
|
@ -56,7 +56,7 @@
|
|||
path
|
||||
params
|
||||
#(dispatch [:suggestions-handler {:command command
|
||||
:content content} %])))))
|
||||
:content content} %]))))
|
||||
|
||||
(register-handler :set-chat-command-content
|
||||
(after invoke-suggestions-handler!)
|
||||
|
@ -67,7 +67,22 @@
|
|||
[{:keys [current-chat-id] :as db} text]
|
||||
(assoc-in db [:chats current-chat-id :input-text] text))
|
||||
|
||||
|
||||
(defn invoke-command-preview!
|
||||
[{:keys [current-chat-id staged-command] :as db} _]
|
||||
(let [commands (get-in db [:chats current-chat-id :commands])
|
||||
{:keys [command content]} staged-command
|
||||
path [(if (commands command) :commands :responses)
|
||||
(:name command)
|
||||
:preview]
|
||||
params {:value content}]
|
||||
(j/call current-chat-id
|
||||
path
|
||||
params
|
||||
#(dispatch [:command-preview current-chat-id %]))))
|
||||
|
||||
(register-handler :stage-command
|
||||
(after invoke-command-preview!)
|
||||
(fn [{:keys [current-chat-id] :as db} _]
|
||||
(let [db (update-input-text db nil)
|
||||
{:keys [command content]}
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
:onPress #(cancel-command-input staged-command)}
|
||||
[image {:source res/icon-close-gray
|
||||
:style st/staged-command-cancel-icon}]]]
|
||||
(if-let [preview (:preview staged-command)]
|
||||
preview
|
||||
[text {:style st/staged-command-content}
|
||||
;; TODO isn't smart
|
||||
(if (= (:command command) :keypair-password)
|
||||
"******"
|
||||
(:content staged-command))]]]))
|
||||
(:content staged-command)])]]))
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
[status-im.utils.utils :refer [http-get toast]]
|
||||
[status-im.components.jail :as j]
|
||||
|
||||
[status-im.components.react :refer [text scroll-view view
|
||||
image touchable-highlight]]
|
||||
[status-im.commands.utils :refer [json->cljs generate-hiccup
|
||||
reg-handler]]))
|
||||
|
||||
|
@ -40,13 +38,25 @@
|
|||
(defn suggestions-handler
|
||||
[db [_ response-json]]
|
||||
(let [response (json->cljs response-json)]
|
||||
(println response)
|
||||
(assoc db :current-suggestion (generate-hiccup response))))
|
||||
|
||||
(defn suggestions-events-handler!
|
||||
[db [[n data]]]
|
||||
(case (keyword n)
|
||||
:set-value (dispatch [:set-chat-command-content data])
|
||||
;; todo show error?
|
||||
nil))
|
||||
|
||||
(defn command-preview
|
||||
[db [chat-id response-json]]
|
||||
(if-let [response (json->cljs response-json)]
|
||||
(let [path [:chats chat-id :staged-commands]
|
||||
commands-cnt (count (get-in db path))]
|
||||
;; todo (dec commands-cnt) looks like hack have to find better way to
|
||||
;; do this
|
||||
(update-in db (conj path (dec commands-cnt)) assoc
|
||||
:preview (generate-hiccup response)
|
||||
:preview-string (str response)))
|
||||
db))
|
||||
|
||||
(reg-handler :init-render-command! init-render-command!)
|
||||
|
@ -55,3 +65,4 @@
|
|||
(reg-handler :command-handler! (u/side-effect! command-nadler!))
|
||||
(reg-handler :suggestions-handler suggestions-handler)
|
||||
(reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!))
|
||||
(reg-handler :command-preview command-preview)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
(ns status-im.commands.utils
|
||||
(:require [clojure.set :as set]
|
||||
[clojure.walk :as w]
|
||||
[status-im.components.react :refer [text scroll-view view
|
||||
image touchable-highlight]]
|
||||
[re-frame.core :refer [register-handler dispatch trim-v debug]]))
|
||||
|
||||
(defn json->cljs [json]
|
||||
|
|
|
@ -29,6 +29,7 @@ Command.prototype.create = function (com) {
|
|||
this.color = com.color;
|
||||
this.icon = com.icon;
|
||||
this.params = com.params || [];
|
||||
this.preview = com.preview;
|
||||
this.addToCatalog();
|
||||
|
||||
return this;
|
||||
|
|
Loading…
Reference in New Issue