Disable send button when no peers are connected.

Previously we were only checking whether `network-status` is equal to
`:offline`, therefore allowing the user to send messages even when no
peers are connected (i.e. the app is displaying Connecting to peers..).

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2018-11-16 12:11:51 +01:00
parent 3b494cfc82
commit 1e5b686027
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
2 changed files with 13 additions and 11 deletions

View File

@ -14,20 +14,20 @@
(animation/timing spin-value {:toValue to-spin-value
:duration 300})))))
(defn sendable? [input-text network-status]
(defn sendable? [input-text offline?]
(let [trimmed (string/trim input-text)]
(not (or (string/blank? trimmed)
(= trimmed "/")
(= :offline network-status)))))
offline?))))
(defview send-button-view []
(letsubs [{:keys [command-completion]} [:chats/selected-chat-command]
{:keys [input-text seq-arg-input-text]} [:chats/current-chat]
network-status [:network-status]
offline? [:offline?]
spin-value (animation/create-value 1)]
{:component-did-update (send-button-view-on-update {:spin-value spin-value
:command-completion command-completion})}
(when (and (sendable? input-text network-status)
(when (and (sendable? input-text offline?)
(or (not command-completion)
(#{:complete :less-than-needed} command-completion)))
[react/touchable-highlight {:on-press #(re-frame/dispatch [:chat.ui/send-current-message])}

View File

@ -48,18 +48,20 @@
(reg-sub :network-status :network-status)
(reg-sub :peers-count :peers-count)
(reg-sub :offline?
:<- [:network-status]
:<- [:sync-state]
(fn [[network-status sync-state]]
(or (= network-status :offline)
(= sync-state :offline))))
(reg-sub :disconnected?
:<- [:peers-count]
(fn [peers-count]
(zero? peers-count)))
(reg-sub :offline?
:<- [:network-status]
:<- [:sync-state]
:<- [:disconnected?]
(fn [[network-status sync-state disconnected?]]
(or disconnected?
(= network-status :offline)
(= sync-state :offline))))
(reg-sub :syncing?
:<- [:sync-state]
(fn [sync-state]