Start single input

Former-commit-id: 5a901e3b9a
This commit is contained in:
virvar 2016-05-23 17:24:27 +03:00
parent 870d8d4026
commit 02e9365bdf
7 changed files with 129 additions and 63 deletions

View File

@ -13,7 +13,8 @@
(dispatch [:cancel-command])) (dispatch [:cancel-command]))
(defn set-input-message [message] (defn set-input-message [message]
(dispatch [:set-chat-command-content message])) (dispatch [:set-chat-command-content message])
(dispatch [:set-chat-input-text message]))
(defn send-command [] (defn send-command []
(dispatch [:stage-command]) (dispatch [:stage-command])
@ -24,6 +25,10 @@
(validator message) (validator message)
(pos? (count message)))) (pos? (count message))))
(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]}] (defn simple-command-input-view [command input-options & {:keys [validator]}]
(let [message-atom (subscribe [:get-chat-command-content])] (let [message-atom (subscribe [:get-chat-command-content])]
(fn [command input-options & {:keys [validator]}] (fn [command input-options & {:keys [validator]}]
@ -31,8 +36,7 @@
[view st/command-input-and-suggestions-container [view st/command-input-and-suggestions-container
[content-suggestions-view] [content-suggestions-view]
[view st/command-input-container [view st/command-input-container
[view (st/command-text-container command) [command-icon command]
[text {:style st/command-text} (:text command)]]
[text-input (merge {:style st/command-input [text-input (merge {:style st/command-input
:autoFocus true :autoFocus true
:onChangeText set-input-message :onChangeText set-input-message
@ -47,3 +51,13 @@
[touchable-highlight {:on-press cancel-command-input} [touchable-highlight {:on-press cancel-command-input}
[view st/cancel-container [view st/cancel-container
[icon :close-gray st/cancel-icon]]])]])))) [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])

View File

@ -2,5 +2,5 @@
(:require (:require
[status-im.chat.views.command :refer [simple-command-input-view]])) [status-im.chat.views.command :refer [simple-command-input-view]]))
(defn confirmation-code-input-view [command] (defn confirmation-code-input-view [command input]
[simple-command-input-view command {:keyboardType :numeric}]) [simple-command-input-view command input {:keyboardType :numeric}])

View File

@ -2,6 +2,6 @@
(:require (:require
[status-im.chat.views.command :refer [simple-command-input-view]])) [status-im.chat.views.command :refer [simple-command-input-view]]))
(defn money-input-view [command] (defn money-input-view [command input]
[simple-command-input-view command [simple-command-input-view command input
{:keyboardType :numeric}]) {:keyboardType :numeric}])

View File

@ -1,14 +1,16 @@
(ns status-im.chat.views.new-message (ns status-im.chat.views.new-message
(:require-macros [status-im.utils.views :refer [defview]])
(:require (:require
[re-frame.core :refer [subscribe]] [re-frame.core :refer [subscribe]]
[status-im.components.react :refer [view]] [status-im.components.react :refer [view]]
[status-im.chat.views.plain-input :refer [plain-message-input-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.command :refer [simple-command-input-view]]
[status-im.chat.views.phone :refer [phone-input-view]] [status-im.chat.views.phone :refer [phone-input-view]]
[status-im.chat.views.password :refer [password-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.confirmation-code :refer [confirmation-code-input-view]]
[status-im.chat.views.money :refer [money-input-view]] [status-im.chat.views.money :refer [money-input-view]]
[status-im.chat.views.staged-command :refer [simple-command-staged-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])) [status-im.chat.styles.message :as st]))
(defn staged-command-view [stage-command] (defn staged-command-view [stage-command]
@ -19,27 +21,44 @@
(for [command staged-commands] (for [command staged-commands]
^{:key command} [staged-command-view command])]) ^{:key command} [staged-command-view command])])
(defn default-command-input-view [command]
[simple-command-input-view command {}])
(defn special-input-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) (case (:command command)
:phone [phone-input-view command] :phone [phone-input-view command input]
:keypair-password [password-input-view command] :keypair-password [password-input-view command input]
:confirmation-code [confirmation-code-input-view command] :confirmation-code [confirmation-code-input-view command input]
:money [money-input-view command] :money [money-input-view command input]
:request [money-input-view command] :request [money-input-view command input]
[default-command-input-view command])) [default-command-input-view command input])))
(defn show-input [command]
[plain-message-input-view
(merge {:command command}
(case (:command command)
:phone {:keyboardType :phone-pad
:validator valid-mobile-number?}
:keypair-password {:secureTextEntry true}
:confirmation-code {:keyboardType :numeric}
:money {:keyboardType :numeric}
:request {:keyboardType :numeric}
nil))])
(defn chat-message-new [] (defn chat-message-new []
(let [command-atom (subscribe [:get-chat-command]) (let [command-atom (subscribe [:get-chat-command])
staged-commands-atom (subscribe [:get-chat-staged-commands])] staged-commands-atom (subscribe [:get-chat-staged-commands])]
(fn [] (fn []
(let [command @command-atom (let [staged-commands @staged-commands-atom]
staged-commands @staged-commands-atom]
[view st/new-message-container [view st/new-message-container
(when (and staged-commands (pos? (count staged-commands))) (when (and staged-commands (pos? (count staged-commands)))
[staged-commands-view staged-commands]) [staged-commands-view staged-commands])
[show-input @command-atom]]))))
(comment
(if command (if command
[special-input-view command] [special-input-view command]
[plain-message-input-view])])))) ))

View File

@ -3,5 +3,5 @@
[status-im.chat.views.command [status-im.chat.views.command
:refer [simple-command-input-view]])) :refer [simple-command-input-view]]))
(defn password-input-view [command] (defn password-input-view [command input]
[simple-command-input-view command {:secureTextEntry true}]) [simple-command-input-view command input {:secureTextEntry true}])

View File

@ -4,6 +4,6 @@
:refer [simple-command-input-view]] :refer [simple-command-input-view]]
[status-im.utils.phone-number :refer [valid-mobile-number?]])) [status-im.utils.phone-number :refer [valid-mobile-number?]]))
(defn phone-input-view [command] (defn phone-input-view [command input]
[simple-command-input-view command {:keyboardType :phone-pad} [simple-command-input-view command input {:keyboardType :phone-pad}
:validator valid-mobile-number?]) :validator valid-mobile-number?])

View File

@ -1,53 +1,86 @@
(ns status-im.chat.views.plain-input (ns status-im.chat.views.plain-input
(:require-macros [status-im.utils.views :refer [defview]])
(:require [re-frame.core :refer [subscribe dispatch]] (:require [re-frame.core :refer [subscribe dispatch]]
[status-im.components.react :refer [view [status-im.components.react :refer [view
icon icon
touchable-highlight touchable-highlight
text-input]] text-input]]
[status-im.chat.views.suggestions :refer [suggestions-view]] [status-im.chat.views.suggestions :refer [suggestions-view]]
[status-im.chat.styles.plain-input :as st])) [status-im.chat.views.content-suggestions :refer [content-suggestions-view]]
[status-im.chat.views.command :as command]
[status-im.chat.styles.plain-input :as st]
[status-im.chat.styles.input :as st-command]))
(defn set-input-message [message] (defn set-input-message [message]
(dispatch [:set-chat-input-text message])) (dispatch [:set-chat-input-text message]))
(defn send [chat input-message] (defn send []
(let [{:keys [group-chat chat-id]} chat] (dispatch [:send-chat-msg]))
(dispatch [:send-chat-msg])))
(defn message-valid? [staged-commands message] (defn message-valid? [staged-commands message]
(or (and (pos? (count message)) (or (and (pos? (count message))
(not= "!" message)) (not= "!" message))
(pos? (count staged-commands)))) (pos? (count staged-commands))))
(defn try-send [chat staged-commands message] (defn try-send [staged-commands message]
(when (message-valid? staged-commands message) (when (message-valid? staged-commands message)
(send chat message))) (send)))
(defn plain-message-input-view [] (defn plain-message-input-view [{:keys [command input-options validator]}]
(let [chat (subscribe [:get-current-chat]) (let [chat (subscribe [:get-current-chat])
input-message-atom (subscribe [:get-chat-input-text]) input-message-atom (subscribe [:get-chat-input-text])
staged-commands-atom (subscribe [:get-chat-staged-commands]) staged-commands-atom (subscribe [:get-chat-staged-commands])
typing-command? (subscribe [:typing-command?])] typing-command? (subscribe [:typing-command?])]
(fn [] (fn [{:keys [command input-options validator]}]
(let [input-message @input-message-atom] (let [input-message @input-message-atom]
[view st/input-container [view st/input-container
[suggestions-view] (if command
[content-suggestions-view]
[suggestions-view])
[view st/input-view [view st/input-view
(if command
[command/command-icon command]
[touchable-highlight {:on-press #(dispatch [:switch-command-suggestions]) [touchable-highlight {:on-press #(dispatch [:switch-command-suggestions])
:style st/switch-commands-touchable} :style st/switch-commands-touchable}
[view nil [view nil
(if @typing-command? (if @typing-command?
[icon :close-gray st/close-icon] [icon :close-gray st/close-icon]
[icon :list st/list-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 [text-input {:style st/message-input
:autoFocus (pos? (count @staged-commands-atom)) :autoFocus (pos? (count @staged-commands-atom))
;:keyboardType (if (< 3 (count input-message)) :default :numeric)
:onChangeText set-input-message :onChangeText set-input-message
:onSubmitEditing #(try-send @chat @staged-commands-atom :onSubmitEditing #(try-send @chat @staged-commands-atom
input-message)} input-message)}
input-message] input-message])
;; TODO emoticons: not implemented
[icon :smile st/smile-icon]
(when (message-valid? @staged-commands-atom input-message)
[touchable-highlight {:on-press #(send @chat input-message)}
[view st/send-container
[icon :send st/send-icon]]])]]))))