Single input
This commit is contained in:
parent
5a901e3b9a
commit
583f424e93
|
@ -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))
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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])
|
|
@ -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}])
|
|
@ -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}])
|
|
@ -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]
|
||||
))
|
|
@ -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}])
|
|
@ -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?])
|
|
@ -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])
|
||||
@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]]]))]])))
|
||||
|
|
Loading…
Reference in New Issue