mirror of
https://github.com/status-im/status-react.git
synced 2025-01-11 11:34:45 +00:00
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))))
|
(update-in [:chats current-chat-id :input-text] safe-trim))))
|
||||||
|
|
||||||
(register-handler :set-chat-command-content
|
(register-handler :set-chat-command-content
|
||||||
(fn [db [_ content]]
|
(fn [{:keys [current-chat-id] :as db} [_ content]]
|
||||||
(commands/set-chat-command-content db content)))
|
(-> db
|
||||||
|
(commands/set-chat-command-content content)
|
||||||
|
(assoc-in [:chats current-chat-id :input-text] nil))))
|
||||||
|
|
||||||
(defn update-input-text
|
(defn update-input-text
|
||||||
[{:keys [current-chat-id] :as db} text]
|
[{:keys [current-chat-id] :as db} text]
|
||||||
@ -68,8 +70,12 @@
|
|||||||
(update-input-text db text))
|
(update-input-text db text))
|
||||||
|
|
||||||
(defn update-command [db [_ text]]
|
(defn update-command [db [_ text]]
|
||||||
|
(if (not (commands/get-chat-command db))
|
||||||
(let [{:keys [command]} (suggestions/check-suggestion db text)]
|
(let [{:keys [command]} (suggestions/check-suggestion db text)]
|
||||||
(commands/set-chat-command db command)))
|
(if command
|
||||||
|
(commands/set-chat-command db command)
|
||||||
|
db))
|
||||||
|
db))
|
||||||
|
|
||||||
(register-handler :set-chat-input-text
|
(register-handler :set-chat-input-text
|
||||||
((enrich update-command) update-text))
|
((enrich update-command) update-text))
|
||||||
|
@ -224,6 +224,7 @@
|
|||||||
:renderScrollComponent #(invertible-scroll-view (js->clj %))
|
:renderScrollComponent #(invertible-scroll-view (js->clj %))
|
||||||
:onEndReached #(dispatch [:load-more-messages])
|
:onEndReached #(dispatch [:load-more-messages])
|
||||||
:enableEmptySections true
|
:enableEmptySections true
|
||||||
|
:keyboardShouldPersistTaps true
|
||||||
:dataSource (to-datasource messages)}]))
|
:dataSource (to-datasource messages)}]))
|
||||||
|
|
||||||
(defview chat []
|
(defview chat []
|
||||||
|
@ -5,16 +5,13 @@
|
|||||||
text
|
text
|
||||||
text-input
|
text-input
|
||||||
touchable-highlight]]
|
touchable-highlight]]
|
||||||
[status-im.chat.views.content-suggestions :refer
|
|
||||||
[content-suggestions-view]]
|
|
||||||
[status-im.chat.styles.input :as st]))
|
[status-im.chat.styles.input :as st]))
|
||||||
|
|
||||||
(defn cancel-command-input []
|
(defn cancel-command-input []
|
||||||
(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])
|
||||||
@ -25,39 +22,10 @@
|
|||||||
(validator message)
|
(validator message)
|
||||||
(pos? (count message))))
|
(pos? (count message))))
|
||||||
|
|
||||||
|
(defn try-send [message validator]
|
||||||
|
(when (valid? message validator)
|
||||||
|
(send-command)))
|
||||||
|
|
||||||
(defn command-icon [command]
|
(defn command-icon [command]
|
||||||
[view (st/command-text-container command)
|
[view (st/command-text-container command)
|
||||||
[text {:style st/command-text} (:text 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
|
(: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 input]]
|
[status-im.chat.views.plain-input :refer [plain-message-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.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.chat.views.staged-command :refer [simple-command-staged-view]]
|
||||||
[status-im.utils.phone-number :refer [valid-mobile-number?]]
|
[status-im.utils.phone-number :refer [valid-mobile-number?]]
|
||||||
[status-im.chat.styles.message :as st]))
|
[status-im.chat.styles.message :as st]))
|
||||||
@ -21,31 +16,16 @@
|
|||||||
(for [command staged-commands]
|
(for [command staged-commands]
|
||||||
^{:key command} [staged-command-view command])])
|
^{: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]
|
(defn show-input [command]
|
||||||
[plain-message-input-view
|
[plain-message-input-view
|
||||||
(merge {:command command}
|
(merge {:command command}
|
||||||
(case (:command command)
|
(case (:command command)
|
||||||
:phone {:keyboardType :phone-pad
|
:phone {:input-options {:keyboardType :phone-pad}
|
||||||
:validator valid-mobile-number?}
|
:validator valid-mobile-number?}
|
||||||
:keypair-password {:secureTextEntry true}
|
:keypair-password {:input-options {:secureTextEntry true}}
|
||||||
:confirmation-code {:keyboardType :numeric}
|
:confirmation-code {:input-options {:keyboardType :numeric}}
|
||||||
:money {:keyboardType :numeric}
|
:money {:input-options {:keyboardType :numeric}}
|
||||||
:request {:keyboardType :numeric}
|
:request {:input-options {:keyboardType :numeric}}
|
||||||
nil))])
|
nil))])
|
||||||
|
|
||||||
(defn chat-message-new []
|
(defn chat-message-new []
|
||||||
@ -57,8 +37,3 @@
|
|||||||
(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]]))))
|
[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,12 +27,11 @@
|
|||||||
(send)))
|
(send)))
|
||||||
|
|
||||||
(defn plain-message-input-view [{:keys [command input-options validator]}]
|
(defn plain-message-input-view [{:keys [command input-options validator]}]
|
||||||
(let [chat (subscribe [:get-current-chat])
|
(let [input-message (subscribe [:get-chat-input-text])
|
||||||
input-message-atom (subscribe [:get-chat-input-text])
|
input-command (subscribe [:get-chat-command-content])
|
||||||
staged-commands-atom (subscribe [:get-chat-staged-commands])
|
staged-commands (subscribe [:get-chat-staged-commands])
|
||||||
typing-command? (subscribe [:typing-command?])]
|
typing-command? (subscribe [:typing-command?])]
|
||||||
(fn [{:keys [command input-options validator]}]
|
(fn [{:keys [command input-options validator]}]
|
||||||
(let [input-message @input-message-atom]
|
|
||||||
[view st/input-container
|
[view st/input-container
|
||||||
(if command
|
(if command
|
||||||
[content-suggestions-view]
|
[content-suggestions-view]
|
||||||
@ -46,41 +45,33 @@
|
|||||||
(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
|
[text-input (merge {:style (if command st-command/command-input st/message-input) ;; st-command/command-input
|
||||||
(merge {:style st-command/command-input
|
:autoFocus false
|
||||||
:autoFocus true
|
:onChangeText (fn [text]
|
||||||
:onChangeText command/set-input-message
|
((if command
|
||||||
|
command/set-input-message
|
||||||
|
set-input-message)
|
||||||
|
text))
|
||||||
:onSubmitEditing (fn []
|
:onSubmitEditing (fn []
|
||||||
(when (command/valid? input-message validator)
|
(if command
|
||||||
(command/send-command)))}
|
(command/try-send @input-command validator)
|
||||||
|
(try-send @staged-commands
|
||||||
|
@input-message)))}
|
||||||
input-options)
|
input-options)
|
||||||
;; plain
|
(if command
|
||||||
{:style st/message-input
|
@input-command
|
||||||
:autoFocus (pos? (count @staged-commands-atom))
|
@input-message)]
|
||||||
:onChangeText set-input-message
|
|
||||||
:onSubmitEditing #(try-send @staged-commands-atom
|
|
||||||
input-message)})
|
|
||||||
input-message]
|
|
||||||
;; TODO emoticons: not implemented
|
;; TODO emoticons: not implemented
|
||||||
(when (not command)
|
(when (not command)
|
||||||
[icon :smile st/smile-icon])
|
[icon :smile st/smile-icon])
|
||||||
(if command
|
(if command
|
||||||
(if (command/valid? input-message validator)
|
(if (command/valid? @input-command validator)
|
||||||
[touchable-highlight {:on-press command/send-command}
|
[touchable-highlight {:on-press command/send-command}
|
||||||
[view st/send-container [icon :send st/send-icon]]]
|
[view st/send-container [icon :send st/send-icon]]]
|
||||||
[touchable-highlight {:on-press command/cancel-command-input}
|
[touchable-highlight {:on-press command/cancel-command-input}
|
||||||
[view st-command/cancel-container
|
[view st-command/cancel-container
|
||||||
[icon :close-gray st-command/cancel-icon]]])
|
[icon :close-gray st-command/cancel-icon]]])
|
||||||
(when (message-valid? @staged-commands-atom input-message)
|
(when (message-valid? @staged-commands @input-message)
|
||||||
[touchable-highlight {:on-press send}
|
[touchable-highlight {:on-press send}
|
||||||
[view st/send-container
|
[view st/send-container
|
||||||
[icon :send st/send-icon]]]))]]))))
|
[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])
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user