[#6415] mark button as inactive when no internet or mailserver connection
Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
parent
66e7815bcc
commit
7a62b4b48b
|
@ -14,20 +14,22 @@
|
||||||
(animation/timing spin-value {:toValue to-spin-value
|
(animation/timing spin-value {:toValue to-spin-value
|
||||||
:duration 300})))))
|
:duration 300})))))
|
||||||
|
|
||||||
(defn sendable? [input-text network-status]
|
(defn sendable? [input-text network-status mailserver-connected?]
|
||||||
(let [trimmed (string/trim input-text)]
|
(let [trimmed (string/trim input-text)]
|
||||||
(not (or (string/blank? trimmed)
|
(not (or (string/blank? trimmed)
|
||||||
(= trimmed "/")
|
(= trimmed "/")
|
||||||
(= :offline network-status)))))
|
(= :offline network-status)
|
||||||
|
(not mailserver-connected?)))))
|
||||||
|
|
||||||
(defview send-button-view []
|
(defview send-button-view []
|
||||||
(letsubs [{:keys [command-completion]} [:selected-chat-command]
|
(letsubs [{:keys [command-completion]} [:selected-chat-command]
|
||||||
{:keys [input-text seq-arg-input-text]} [:get-current-chat]
|
{:keys [input-text seq-arg-input-text]} [:get-current-chat]
|
||||||
network-status [:network-status]
|
network-status [:network-status]
|
||||||
|
mailserver-connected? [:mailserver-connected?]
|
||||||
spin-value (animation/create-value 1)]
|
spin-value (animation/create-value 1)]
|
||||||
{:component-did-update (send-button-view-on-update {:spin-value spin-value
|
{:component-did-update (send-button-view-on-update {:spin-value spin-value
|
||||||
:command-completion command-completion})}
|
:command-completion command-completion})}
|
||||||
(when (and (sendable? input-text network-status)
|
(when (and (sendable? input-text network-status mailserver-connected?)
|
||||||
(or (not command-completion)
|
(or (not command-completion)
|
||||||
(#{:complete :less-than-needed} command-completion)))
|
(#{:complete :less-than-needed} command-completion)))
|
||||||
[react/touchable-highlight {:on-press #(re-frame/dispatch [:chat.ui/send-current-message])}
|
[react/touchable-highlight {:on-press #(re-frame/dispatch [:chat.ui/send-current-message])}
|
||||||
|
|
|
@ -251,16 +251,20 @@
|
||||||
:current-public-key current-public-key)]))]]
|
:current-public-key current-public-key)]))]]
|
||||||
[connectivity/error-view]])))
|
[connectivity/error-view]])))
|
||||||
|
|
||||||
(views/defview send-button [inp-ref]
|
(views/defview send-button [inp-ref network-status mailserver-connected?]
|
||||||
(views/letsubs [{:keys [input-text]} [:get-current-chat]]
|
(views/letsubs [{:keys [input-text]} [:get-current-chat]]
|
||||||
(let [empty? (= "" input-text)]
|
(let [empty? (= "" input-text)
|
||||||
|
offline? (= :offline network-status)
|
||||||
|
inactive? (or empty? offline? (not mailserver-connected?))]
|
||||||
[react/touchable-highlight {:style styles/send-button
|
[react/touchable-highlight {:style styles/send-button
|
||||||
|
:disabled inactive?
|
||||||
:on-press (fn []
|
:on-press (fn []
|
||||||
(.clear @inp-ref)
|
(when-not inactive?
|
||||||
(.focus @inp-ref)
|
(.clear @inp-ref)
|
||||||
(re-frame/dispatch [:chat.ui/send-current-message]))}
|
(.focus @inp-ref)
|
||||||
[react/view {:style (styles/send-icon empty?)}
|
(re-frame/dispatch [:chat.ui/send-current-message])))}
|
||||||
[icons/icon :icons/arrow-left {:style (styles/send-icon-arrow empty?)}]]])))
|
[react/view {:style (styles/send-icon inactive?)}
|
||||||
|
[icons/icon :icons/arrow-left {:style (styles/send-icon-arrow inactive?)}]]])))
|
||||||
|
|
||||||
(views/defview reply-message [from message-text]
|
(views/defview reply-message [from message-text]
|
||||||
(views/letsubs [username [:get-contact-name-by-identity from]
|
(views/letsubs [username [:get-contact-name-by-identity from]
|
||||||
|
@ -292,7 +296,9 @@
|
||||||
[icons/icon :icons/close {:style styles/reply-close-icon}]]]])))
|
[icons/icon :icons/close {:style styles/reply-close-icon}]]]])))
|
||||||
|
|
||||||
(views/defview chat-text-input [chat-id input-text]
|
(views/defview chat-text-input [chat-id input-text]
|
||||||
(views/letsubs [inp-ref (atom nil)]
|
(views/letsubs [inp-ref (atom nil)
|
||||||
|
network-status [:network-status]
|
||||||
|
mailserver-connected? [:mailserver-connected?]]
|
||||||
{:component-will-update
|
{:component-will-update
|
||||||
(fn [e [_ new-chat-id new-input-text]]
|
(fn [e [_ new-chat-id new-input-text]]
|
||||||
(let [[_ old-chat-id] (.. e -props -argv)]
|
(let [[_ old-chat-id] (.. e -props -argv)]
|
||||||
|
@ -313,14 +319,16 @@
|
||||||
:default-value input-text
|
:default-value input-text
|
||||||
:on-content-size-change #(set-container-height-fn (.-height (.-contentSize (.-nativeEvent %))))
|
:on-content-size-change #(set-container-height-fn (.-height (.-contentSize (.-nativeEvent %))))
|
||||||
:submit-shortcut {:key "Enter"}
|
:submit-shortcut {:key "Enter"}
|
||||||
:on-submit-editing #(do (.clear @inp-ref)
|
:on-submit-editing #(when (and (= :online network-status)
|
||||||
(.focus @inp-ref)
|
mailserver-connected?)
|
||||||
(re-frame/dispatch [:chat.ui/send-current-message]))
|
(.clear @inp-ref)
|
||||||
|
(.focus @inp-ref)
|
||||||
|
(re-frame/dispatch [:chat.ui/send-current-message]))
|
||||||
:on-change (fn [e]
|
:on-change (fn [e]
|
||||||
(let [native-event (.-nativeEvent e)
|
(let [native-event (.-nativeEvent e)
|
||||||
text (.-text native-event)]
|
text (.-text native-event)]
|
||||||
(re-frame/dispatch [:chat.ui/set-chat-input-text text])))}]
|
(re-frame/dispatch [:chat.ui/set-chat-input-text text])))}]
|
||||||
[send-button inp-ref]])))
|
[send-button inp-ref network-status mailserver-connected?]])))
|
||||||
|
|
||||||
(views/defview chat-view []
|
(views/defview chat-view []
|
||||||
(views/letsubs [{:keys [input-text chat-id] :as current-chat} [:get-current-chat]]
|
(views/letsubs [{:keys [input-text chat-id] :as current-chat} [:get-current-chat]]
|
||||||
|
|
|
@ -72,6 +72,11 @@
|
||||||
(fn [mailserver-status]
|
(fn [mailserver-status]
|
||||||
(#{:error :disconnected} mailserver-status)))
|
(#{:error :disconnected} mailserver-status)))
|
||||||
|
|
||||||
|
(reg-sub :mailserver-connected?
|
||||||
|
:<- [:mailserver-status]
|
||||||
|
(fn [mailserver-status]
|
||||||
|
(= :connected mailserver-status)))
|
||||||
|
|
||||||
(reg-sub :syncing?
|
(reg-sub :syncing?
|
||||||
:<- [:sync-state]
|
:<- [:sync-state]
|
||||||
(fn [sync-state]
|
(fn [sync-state]
|
||||||
|
|
Loading…
Reference in New Issue