From 950251a28118373eb50b2483e299a3eabcb81b9d Mon Sep 17 00:00:00 2001 From: virvar Date: Tue, 24 May 2016 16:34:46 +0300 Subject: [PATCH] Single input Former-commit-id: 583f424e93b2b15b1a5e6d014db73f61a103b88b --- src/status_im/chat/handlers.cljs | 14 ++- src/status_im/chat/screen.cljs | 11 ++- src/status_im/chat/views/command.cljs | 42 +------- .../chat/views/confirmation_code.cljs | 6 -- src/status_im/chat/views/money.cljs | 7 -- src/status_im/chat/views/new_message.cljs | 37 ++----- src/status_im/chat/views/password.cljs | 7 -- src/status_im/chat/views/phone.cljs | 9 -- src/status_im/chat/views/plain_input.cljs | 99 +++++++++---------- 9 files changed, 72 insertions(+), 160 deletions(-) delete mode 100644 src/status_im/chat/views/confirmation_code.cljs delete mode 100644 src/status_im/chat/views/money.cljs delete mode 100644 src/status_im/chat/views/password.cljs delete mode 100644 src/status_im/chat/views/phone.cljs diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 011749f25f..5b8a8bc030 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -42,8 +42,10 @@ (update-in [:chats current-chat-id :input-text] safe-trim)))) (register-handler :set-chat-command-content - (fn [db [_ content]] - (commands/set-chat-command-content db content))) + (fn [{:keys [current-chat-id] :as db} [_ content]] + (-> db + (commands/set-chat-command-content content) + (assoc-in [:chats current-chat-id :input-text] nil)))) (defn update-input-text [{:keys [current-chat-id] :as db} text] @@ -68,8 +70,12 @@ (update-input-text db text)) (defn update-command [db [_ text]] - (let [{:keys [command]} (suggestions/check-suggestion db text)] - (commands/set-chat-command db command))) + (if (not (commands/get-chat-command db)) + (let [{:keys [command]} (suggestions/check-suggestion db text)] + (if command + (commands/set-chat-command db command) + db)) + db)) (register-handler :set-chat-input-text ((enrich update-command) update-text)) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 19723aba22..2ed10ba018 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -220,11 +220,12 @@ [messages [:chat :messages] contacts [:chat :contacts]] (let [contacts' (contacts-by-identity contacts)] - [list-view {:renderRow (message-row contacts' group-chat) - :renderScrollComponent #(invertible-scroll-view (js->clj %)) - :onEndReached #(dispatch [:load-more-messages]) - :enableEmptySections true - :dataSource (to-datasource messages)}])) + [list-view {:renderRow (message-row contacts' group-chat) + :renderScrollComponent #(invertible-scroll-view (js->clj %)) + :onEndReached #(dispatch [:load-more-messages]) + :enableEmptySections true + :keyboardShouldPersistTaps true + :dataSource (to-datasource messages)}])) (defview chat [] [group-chat [:chat :group-chat] diff --git a/src/status_im/chat/views/command.cljs b/src/status_im/chat/views/command.cljs index b587e0ab80..b15f08673f 100644 --- a/src/status_im/chat/views/command.cljs +++ b/src/status_im/chat/views/command.cljs @@ -5,16 +5,13 @@ text text-input touchable-highlight]] - [status-im.chat.views.content-suggestions :refer - [content-suggestions-view]] [status-im.chat.styles.input :as st])) (defn cancel-command-input [] (dispatch [:cancel-command])) (defn set-input-message [message] - (dispatch [:set-chat-command-content message]) - (dispatch [:set-chat-input-text message])) + (dispatch [:set-chat-command-content message])) (defn send-command [] (dispatch [:stage-command]) @@ -25,39 +22,10 @@ (validator message) (pos? (count message)))) +(defn try-send [message validator] + (when (valid? message validator) + (send-command))) + (defn command-icon [command] [view (st/command-text-container command) [text {:style st/command-text} (:text command)]]) - -(defn simple-command-input-view [command input-options & {:keys [validator]}] - (let [message-atom (subscribe [:get-chat-command-content])] - (fn [command input-options & {:keys [validator]}] - (let [message @message-atom] - [view st/command-input-and-suggestions-container - [content-suggestions-view] - [view st/command-input-container - [command-icon command] - [text-input (merge {:style st/command-input - :autoFocus true - :onChangeText set-input-message - :onSubmitEditing (fn [] - (when (valid? message validator) - (send-command)))} - input-options) - message] - (if (valid? message validator) - [touchable-highlight {:on-press send-command} - [view st/send-container [icon :send st/send-icon]]] - [touchable-highlight {:on-press cancel-command-input} - [view st/cancel-container - [icon :close-gray st/cancel-icon]]])]])))) - - -(comment [text-input (merge {:style st/command-input - :autoFocus true - :onChangeText set-input-message - :onSubmitEditing (fn [] - (when (valid? message validator) - (send-command)))} - input-options) - message]) \ No newline at end of file diff --git a/src/status_im/chat/views/confirmation_code.cljs b/src/status_im/chat/views/confirmation_code.cljs deleted file mode 100644 index 8b42e446b5..0000000000 --- a/src/status_im/chat/views/confirmation_code.cljs +++ /dev/null @@ -1,6 +0,0 @@ -(ns status-im.chat.views.confirmation-code - (:require - [status-im.chat.views.command :refer [simple-command-input-view]])) - -(defn confirmation-code-input-view [command input] - [simple-command-input-view command input {:keyboardType :numeric}]) diff --git a/src/status_im/chat/views/money.cljs b/src/status_im/chat/views/money.cljs deleted file mode 100644 index 43cde52001..0000000000 --- a/src/status_im/chat/views/money.cljs +++ /dev/null @@ -1,7 +0,0 @@ -(ns status-im.chat.views.money - (:require - [status-im.chat.views.command :refer [simple-command-input-view]])) - -(defn money-input-view [command input] - [simple-command-input-view command input - {:keyboardType :numeric}]) diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index 7ed07c6ff3..73e5466344 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -3,12 +3,7 @@ (:require [re-frame.core :refer [subscribe]] [status-im.components.react :refer [view]] - [status-im.chat.views.plain-input :refer [plain-message-input-view input]] - [status-im.chat.views.command :refer [simple-command-input-view]] - [status-im.chat.views.phone :refer [phone-input-view]] - [status-im.chat.views.password :refer [password-input-view]] - [status-im.chat.views.confirmation-code :refer [confirmation-code-input-view]] - [status-im.chat.views.money :refer [money-input-view]] + [status-im.chat.views.plain-input :refer [plain-message-input-view]] [status-im.chat.views.staged-command :refer [simple-command-staged-view]] [status-im.utils.phone-number :refer [valid-mobile-number?]] [status-im.chat.styles.message :as st])) @@ -21,31 +16,16 @@ (for [command staged-commands] ^{:key command} [staged-command-view command])]) - - -(comment - (defn default-command-input-view [command input] - [simple-command-input-view command input {}]) - - (defn special-input-view [input command] - (case (:command command) - :phone [phone-input-view command input] - :keypair-password [password-input-view command input] - :confirmation-code [confirmation-code-input-view command input] - :money [money-input-view command input] - :request [money-input-view command input] - [default-command-input-view command input]))) - (defn show-input [command] [plain-message-input-view (merge {:command command} (case (:command command) - :phone {:keyboardType :phone-pad + :phone {:input-options {:keyboardType :phone-pad} :validator valid-mobile-number?} - :keypair-password {:secureTextEntry true} - :confirmation-code {:keyboardType :numeric} - :money {:keyboardType :numeric} - :request {:keyboardType :numeric} + :keypair-password {:input-options {:secureTextEntry true}} + :confirmation-code {:input-options {:keyboardType :numeric}} + :money {:input-options {:keyboardType :numeric}} + :request {:input-options {:keyboardType :numeric}} nil))]) (defn chat-message-new [] @@ -57,8 +37,3 @@ (when (and staged-commands (pos? (count staged-commands))) [staged-commands-view staged-commands]) [show-input @command-atom]])))) - -(comment - (if command - [special-input-view command] - )) \ No newline at end of file diff --git a/src/status_im/chat/views/password.cljs b/src/status_im/chat/views/password.cljs deleted file mode 100644 index f8db369e3c..0000000000 --- a/src/status_im/chat/views/password.cljs +++ /dev/null @@ -1,7 +0,0 @@ -(ns status-im.chat.views.password - (:require - [status-im.chat.views.command - :refer [simple-command-input-view]])) - -(defn password-input-view [command input] - [simple-command-input-view command input {:secureTextEntry true}]) diff --git a/src/status_im/chat/views/phone.cljs b/src/status_im/chat/views/phone.cljs deleted file mode 100644 index f35881fc07..0000000000 --- a/src/status_im/chat/views/phone.cljs +++ /dev/null @@ -1,9 +0,0 @@ -(ns status-im.chat.views.phone - (:require - [status-im.chat.views.command - :refer [simple-command-input-view]] - [status-im.utils.phone-number :refer [valid-mobile-number?]])) - -(defn phone-input-view [command input] - [simple-command-input-view command input {:keyboardType :phone-pad} - :validator valid-mobile-number?]) diff --git a/src/status_im/chat/views/plain_input.cljs b/src/status_im/chat/views/plain_input.cljs index f31ff76c48..f3ee1f9fa9 100644 --- a/src/status_im/chat/views/plain_input.cljs +++ b/src/status_im/chat/views/plain_input.cljs @@ -27,60 +27,51 @@ (send))) (defn plain-message-input-view [{:keys [command input-options validator]}] - (let [chat (subscribe [:get-current-chat]) - input-message-atom (subscribe [:get-chat-input-text]) - staged-commands-atom (subscribe [:get-chat-staged-commands]) + (let [input-message (subscribe [:get-chat-input-text]) + input-command (subscribe [:get-chat-command-content]) + staged-commands (subscribe [:get-chat-staged-commands]) typing-command? (subscribe [:typing-command?])] (fn [{:keys [command input-options validator]}] - (let [input-message @input-message-atom] - [view st/input-container + [view st/input-container + (if command + [content-suggestions-view] + [suggestions-view]) + [view st/input-view + (if command + [command/command-icon command] + [touchable-highlight {:on-press #(dispatch [:switch-command-suggestions]) + :style st/switch-commands-touchable} + [view nil + (if @typing-command? + [icon :close-gray st/close-icon] + [icon :list st/list-icon])]]) + [text-input (merge {:style (if command st-command/command-input st/message-input) ;; st-command/command-input + :autoFocus false + :onChangeText (fn [text] + ((if command + command/set-input-message + set-input-message) + text)) + :onSubmitEditing (fn [] + (if command + (command/try-send @input-command validator) + (try-send @staged-commands + @input-message)))} + input-options) (if command - [content-suggestions-view] - [suggestions-view]) - [view st/input-view - (if command - [command/command-icon command] - [touchable-highlight {:on-press #(dispatch [:switch-command-suggestions]) - :style st/switch-commands-touchable} - [view nil - (if @typing-command? - [icon :close-gray st/close-icon] - [icon :list st/list-icon])]]) - [text-input (if command - (merge {:style st-command/command-input - :autoFocus true - :onChangeText command/set-input-message - :onSubmitEditing (fn [] - (when (command/valid? input-message validator) - (command/send-command)))} - input-options) - ;; plain - {:style st/message-input - :autoFocus (pos? (count @staged-commands-atom)) - :onChangeText set-input-message - :onSubmitEditing #(try-send @staged-commands-atom - input-message)}) - input-message] - ;; TODO emoticons: not implemented - (when (not command) - [icon :smile st/smile-icon]) - (if command - (if (command/valid? input-message validator) - [touchable-highlight {:on-press command/send-command} - [view st/send-container [icon :send st/send-icon]]] - [touchable-highlight {:on-press command/cancel-command-input} - [view st-command/cancel-container - [icon :close-gray st-command/cancel-icon]]]) - (when (message-valid? @staged-commands-atom input-message) - [touchable-highlight {:on-press send} - [view st/send-container - [icon :send st/send-icon]]]))]])))) - -(comment - [text-input {:style st/message-input - :autoFocus (pos? (count @staged-commands-atom)) - ;:keyboardType (if (< 3 (count input-message)) :default :numeric) - :onChangeText set-input-message - :onSubmitEditing #(try-send @chat @staged-commands-atom - input-message)} - input-message]) \ No newline at end of file + @input-command + @input-message)] + ;; TODO emoticons: not implemented + (when (not command) + [icon :smile st/smile-icon]) + (if command + (if (command/valid? @input-command validator) + [touchable-highlight {:on-press command/send-command} + [view st/send-container [icon :send st/send-icon]]] + [touchable-highlight {:on-press command/cancel-command-input} + [view st-command/cancel-container + [icon :close-gray st-command/cancel-icon]]]) + (when (message-valid? @staged-commands @input-message) + [touchable-highlight {:on-press send} + [view st/send-container + [icon :send st/send-icon]]]))]])))