some refactoring
This commit is contained in:
parent
d298a142f7
commit
6299e7d686
|
@ -1,13 +1,15 @@
|
||||||
(ns status-im.chat.subs
|
(ns status-im.chat.subs
|
||||||
(:require-macros [reagent.ratom :refer [reaction]])
|
(:require-macros [reagent.ratom :refer [reaction]])
|
||||||
(:require [re-frame.core :refer [register-sub dispatch]]
|
(:require [re-frame.core :refer [register-sub dispatch subscribe]]
|
||||||
[status-im.db :as db]
|
[status-im.db :as db]
|
||||||
;todo handlers in subs?...
|
;todo handlers in subs?...
|
||||||
[status-im.chat.suggestions :refer
|
[status-im.chat.suggestions :refer
|
||||||
[get-suggestions typing-command?]]
|
[get-suggestions typing-command?]]
|
||||||
[status-im.models.commands :as commands]
|
[status-im.models.commands :as commands]
|
||||||
[status-im.constants :refer [response-suggesstion-resize-duration]]
|
[status-im.constants :refer [response-suggesstion-resize-duration]]
|
||||||
[status-im.handlers.content-suggestions :refer [get-content-suggestions]]))
|
[status-im.handlers.content-suggestions :refer [get-content-suggestions]]
|
||||||
|
[status-im.chat.views.plain-message :as plain-message]
|
||||||
|
[status-im.chat.views.command :as command]))
|
||||||
|
|
||||||
(register-sub :chat-properties
|
(register-sub :chat-properties
|
||||||
(fn [db [_ properties]]
|
(fn [db [_ properties]]
|
||||||
|
@ -63,6 +65,18 @@
|
||||||
(get-in @db)
|
(get-in @db)
|
||||||
(reaction))))
|
(reaction))))
|
||||||
|
|
||||||
|
(register-sub :valid-plain-message?
|
||||||
|
(fn [_ _]
|
||||||
|
(let [input-message (subscribe [:get-chat-input-text])
|
||||||
|
staged-commands (subscribe [:get-chat-staged-commands])]
|
||||||
|
(reaction
|
||||||
|
(plain-message/message-valid? @staged-commands @input-message)))))
|
||||||
|
|
||||||
|
(register-sub :valid-command?
|
||||||
|
(fn [_ [_ validator]]
|
||||||
|
(let [input (subscribe [:get-chat-command-content])]
|
||||||
|
(reaction (command/valid? @input validator)))))
|
||||||
|
|
||||||
(register-sub :get-chat-command
|
(register-sub :get-chat-command
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(reaction (commands/get-chat-command @db))))
|
(reaction (commands/get-chat-command @db))))
|
||||||
|
|
|
@ -11,10 +11,8 @@
|
||||||
[status-im.components.animation :as anim]
|
[status-im.components.animation :as anim]
|
||||||
[status-im.chat.views.plain-message :as plain-message]
|
[status-im.chat.views.plain-message :as plain-message]
|
||||||
[status-im.chat.views.command :as command]
|
[status-im.chat.views.command :as command]
|
||||||
[status-im.chat.views.response :as response]
|
|
||||||
[status-im.chat.styles.message-input :as st]
|
[status-im.chat.styles.message-input :as st]
|
||||||
[status-im.chat.styles.plain-message :as st-message]
|
[status-im.chat.styles.plain-message :as st-message]
|
||||||
[status-im.chat.styles.input :as st-command]
|
|
||||||
[status-im.chat.styles.response :as st-response]
|
[status-im.chat.styles.response :as st-response]
|
||||||
[status-im.constants :refer [response-input-hiding-duration]]))
|
[status-im.constants :refer [response-input-hiding-duration]]))
|
||||||
|
|
||||||
|
@ -36,58 +34,42 @@
|
||||||
(defn message-input-container [input]
|
(defn message-input-container [input]
|
||||||
[view st/message-input-container input])
|
[view st/message-input-container input])
|
||||||
|
|
||||||
(defview message-input [input-options validator]
|
(defview message-input [input-options]
|
||||||
[input-message [:get-chat-input-text]
|
[command? [:animations :command?]
|
||||||
command [:get-chat-command]
|
input-message [:get-chat-input-text]
|
||||||
command? [:animations :command?]
|
input-command [:get-chat-command-content]]
|
||||||
to-msg-id [:get-chat-command-to-msg-id]
|
[text-input (merge {:style (if command?
|
||||||
input-command [:get-chat-command-content]
|
st-response/command-input
|
||||||
staged-commands [:get-chat-staged-commands]
|
st-message/message-input)
|
||||||
typing-command? [:typing-command?]]
|
:ref #(dispatch [:set-message-input %])
|
||||||
(let [dismiss-keyboard (not (or command typing-command?))]
|
:autoFocus false
|
||||||
[text-input (merge {:style (if command?
|
:blurOnSubmit false
|
||||||
st-response/command-input
|
:onChangeText (if command?
|
||||||
st-message/message-input)
|
command/set-input-message
|
||||||
:ref #(dispatch [:set-message-input %])
|
plain-message/set-input-message)
|
||||||
:autoFocus false
|
:onSubmitEditing (if command?
|
||||||
:blurOnSubmit dismiss-keyboard
|
command/send-command
|
||||||
:onChangeText (if command?
|
plain-message/send)}
|
||||||
command/set-input-message
|
(when command?
|
||||||
plain-message/set-input-message)
|
{:accessibility-label :command-input})
|
||||||
:onSubmitEditing #(if command?
|
input-options)
|
||||||
(command/try-send input-command validator)
|
(if command? input-command input-message)])
|
||||||
(plain-message/try-send staged-commands
|
|
||||||
input-message
|
|
||||||
dismiss-keyboard))}
|
|
||||||
(when command?
|
|
||||||
{:accessibility-label :command-input})
|
|
||||||
input-options)
|
|
||||||
(if command?
|
|
||||||
input-command
|
|
||||||
input-message)]))
|
|
||||||
|
|
||||||
(defview plain-message-input-view [{:keys [input-options validator]}]
|
(defview plain-message-input-view [{:keys [input-options validator]}]
|
||||||
[input-message [:get-chat-input-text]
|
[command? [:animations :command?]
|
||||||
command [:get-chat-command]
|
|
||||||
command? [:animations :command?]
|
|
||||||
to-msg-id [:get-chat-command-to-msg-id]
|
|
||||||
input-command [:get-chat-command-content]
|
input-command [:get-chat-command-content]
|
||||||
staged-commands [:get-chat-staged-commands]
|
valid-plain-message? [:valid-plain-message?]
|
||||||
typing-command? [:typing-command?]]
|
valid-command? [:valid-command? validator]]
|
||||||
(let [dismiss-keyboard (not (or command typing-command?))]
|
[view st/input-container
|
||||||
[view st/input-container
|
[view st/input-view
|
||||||
[view st/input-view
|
[plain-message/commands-button]
|
||||||
[plain-message/commands-button]
|
[message-input-container
|
||||||
[message-input-container
|
[message-input input-options validator]]
|
||||||
[message-input input-options validator]]
|
;; TODO emoticons: not implemented
|
||||||
;; TODO emoticons: not implemented
|
[plain-message/smile-button]
|
||||||
[plain-message/smile-button]
|
(when (if command? valid-command? valid-plain-message?)
|
||||||
(if-not command?
|
(let [on-press (if command?
|
||||||
(when (plain-message/message-valid? staged-commands input-message)
|
command/send-command
|
||||||
[send-button {:on-press #(plain-message/try-send staged-commands
|
plain-message/send)]
|
||||||
input-message
|
[send-button {:on-press on-press
|
||||||
dismiss-keyboard)
|
:accessibility-label :send-message}]))]])
|
||||||
:accessibility-label :send-message}])
|
|
||||||
(when (command/valid? input-command validator)
|
|
||||||
[send-button {:on-press command/send-command
|
|
||||||
:accessibility-label :stage-command}]))]]))
|
|
||||||
|
|
|
@ -14,9 +14,7 @@
|
||||||
(defn set-input-message [message]
|
(defn set-input-message [message]
|
||||||
(dispatch [:set-chat-input-text message]))
|
(dispatch [:set-chat-input-text message]))
|
||||||
|
|
||||||
(defn send [dismiss-keyboard]
|
(defn send []
|
||||||
(when dismiss-keyboard
|
|
||||||
(dismiss-keyboard!))
|
|
||||||
(dispatch [:send-chat-msg]))
|
(dispatch [:send-chat-msg]))
|
||||||
|
|
||||||
(defn message-valid? [staged-commands message]
|
(defn message-valid? [staged-commands message]
|
||||||
|
@ -24,15 +22,6 @@
|
||||||
(not= "!" message))
|
(not= "!" message))
|
||||||
(pos? (count staged-commands))))
|
(pos? (count staged-commands))))
|
||||||
|
|
||||||
(defn try-send [staged-commands message dismiss-keyboard]
|
|
||||||
(when (message-valid? staged-commands message)
|
|
||||||
(send dismiss-keyboard)))
|
|
||||||
|
|
||||||
(defn prepare-message-input [message-input]
|
|
||||||
(when message-input
|
|
||||||
(.clear message-input)
|
|
||||||
(.focus message-input)))
|
|
||||||
|
|
||||||
(defn button-animation-logic [{:keys [command? val]}]
|
(defn button-animation-logic [{:keys [command? val]}]
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(let [to-scale (if @command? 0 1)]
|
(let [to-scale (if @command? 0 1)]
|
||||||
|
|
Loading…
Reference in New Issue