Start single input

This commit is contained in:
virvar 2016-05-23 17:24:27 +03:00
parent 00145a8c6f
commit 5a901e3b9a
7 changed files with 129 additions and 63 deletions

View File

@ -1,10 +1,10 @@
(ns status-im.chat.views.command
(:require [re-frame.core :refer [subscribe dispatch]]
[status-im.components.react :refer [view
icon
text
text-input
touchable-highlight]]
icon
text
text-input
touchable-highlight]]
[status-im.chat.views.content-suggestions :refer
[content-suggestions-view]]
[status-im.chat.styles.input :as st]))
@ -13,7 +13,8 @@
(dispatch [:cancel-command]))
(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 []
(dispatch [:stage-command])
@ -24,6 +25,10 @@
(validator 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]}]
(let [message-atom (subscribe [:get-chat-command-content])]
(fn [command input-options & {:keys [validator]}]
@ -31,8 +36,7 @@
[view st/command-input-and-suggestions-container
[content-suggestions-view]
[view st/command-input-container
[view (st/command-text-container command)
[text {:style st/command-text} (:text command)]]
[command-icon command]
[text-input (merge {:style st/command-input
:autoFocus true
:onChangeText set-input-message
@ -47,3 +51,13 @@
[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])

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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