From 5e94fb9b7b255fd9534ad49c2d7594787f8b42b6 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 18:38:44 +0300 Subject: [PATCH] first parameter Former-commit-id: 013e4e79ae3c7336c5b6a4d502cd7aa25e1bc1c5 --- resources/commands.js | 10 +++++---- resources/status.js | 5 +++-- src/status_im/android/core.cljs | 1 - src/status_im/chat/subs.cljs | 9 ++++++++ src/status_im/chat/views/new_message.cljs | 26 +++++++++++++---------- src/status_im/models/commands.cljs | 7 +++--- 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/resources/commands.js b/resources/commands.js index 94c631b979..ee5cac345b 100644 --- a/resources/commands.js +++ b/resources/commands.js @@ -4,7 +4,8 @@ status.command({ color: "#9a5dcf" }).param({ name: "address", - type: status.types.STRING + type: status.types.TEXT, + placeholder: "Address" }); var phones = [ @@ -110,8 +111,9 @@ status.response({ color: "#5fc48d", params: [{ name: "phone", - type: status.types.PHONE_NUMBER, - suggestions: phoneSuggestions + type: status.types.PHONE, + suggestions: phoneSuggestions, + placeholder: "Phone number" }], handler: function (params) { return { @@ -127,7 +129,7 @@ status.command({ color: "#7099e6", params: [{ name: "query", - type: status.types.STRING + type: status.types.TEXT }] }); diff --git a/resources/status.js b/resources/status.js index 924decbf47..2eec9a3d44 100644 --- a/resources/status.js +++ b/resources/status.js @@ -92,8 +92,9 @@ var status = { return response.create(n, d, h); }, types: { - STRING: 'string', - PHONE_NUMBER: 'phone-number', + TEXT: 'text', + NUMBER: 'number', + PHONE: 'phone', PASSWORD: 'password' }, events: { diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index e20c9fcfc1..e69e22cc2f 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -82,7 +82,6 @@ (dispatch [:initialize-protocol]) (dispatch [:load-user-phone-number]) (dispatch [:load-contacts]) - ;; load commands from remote server (todo: uncomment) (dispatch [:init-console-chat]) (dispatch [:init-chat]) (init-back-button-handler!) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index c5340917e0..b9f08f0402 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -87,6 +87,15 @@ (fn [db _] (reaction (commands/get-chat-command @db)))) +(register-sub :get-command-parameter + (fn [db] + (let [command (subscribe [:get-chat-command]) + chat-id (subscribe [:get-current-chat-id])] + (reaction + (let [path [:chats @chat-id :command-input :parameter-idx] + n (get-in @db path)] + (when n (nth (:params @command) n))))))) + (register-sub :get-chat-command-content (fn [db _] (reaction (commands/get-chat-command-content @db)))) diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index 1434651b1f..2a1e2cd892 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -16,20 +16,24 @@ (for [command staged-commands] ^{:key command} [staged-command-view command])]) +(defn get-options [{:keys [type placeholder]}] + (let [options (case (keyword type) + :phone {:input-options {:keyboardType :phone-pad} + :validator valid-mobile-number?} + :password {:input-options {:secureTextEntry true}} + :number {:input-options {:keyboardType :numeric}} + ;; todo maybe nil is fine for now :) + nil #_(throw (js/Error. "Uknown command type")))] + (println :plc placeholder) + (if placeholder + (assoc-in options [:input-options :placeholder] placeholder) + options))) + (defview show-input [] - [command [:get-chat-command] + [parameter [:get-command-parameter] command? [:command?]] [plain-message-input-view - (when command? - (case (keyword (:name command)) - :phone {:input-options {:keyboardType :phone-pad} - :validator valid-mobile-number?} - :keypair {:input-options {:secureTextEntry true}} - :confirmation-code {:input-options {:keyboardType :numeric}} - :money {:input-options {:keyboardType :numeric}} - :request {:input-options {:keyboardType :numeric}} - ;; todo maybe nil is fine for now :) - nil #_(throw (js/Error. "Uknown command type"))))]) + (when command? (get-options parameter))]) (defview chat-message-new [] [staged-commands [:get-chat-staged-commands]] diff --git a/src/status_im/models/commands.cljs b/src/status_im/models/commands.cljs index aa426640eb..1ebb70dccb 100644 --- a/src/status_im/models/commands.cljs +++ b/src/status_im/models/commands.cljs @@ -34,9 +34,10 @@ (defn set-response-chat-command [{:keys [current-chat-id] :as db} msg-id command-key] (update-in db [:chats current-chat-id :command-input] merge - {:content nil - :command (get-command db command-key) - :to-msg-id msg-id})) + {:content nil + :command (get-command db command-key) + :parameter-idx 0 + :to-msg-id msg-id})) (defn set-chat-command [db command-key] (set-response-chat-command db nil command-key))