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:
parent
3b494cfc82
commit
1e5b686027
|
@ -14,20 +14,20 @@
|
||||||
(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 offline?]
|
||||||
(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?))))
|
||||||
|
|
||||||
(defview send-button-view []
|
(defview send-button-view []
|
||||||
(letsubs [{:keys [command-completion]} [:chats/selected-chat-command]
|
(letsubs [{:keys [command-completion]} [:chats/selected-chat-command]
|
||||||
{:keys [input-text seq-arg-input-text]} [:chats/current-chat]
|
{:keys [input-text seq-arg-input-text]} [:chats/current-chat]
|
||||||
network-status [:network-status]
|
offline? [:offline?]
|
||||||
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 offline?)
|
||||||
(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])}
|
||||||
|
|
|
@ -48,18 +48,20 @@
|
||||||
(reg-sub :network-status :network-status)
|
(reg-sub :network-status :network-status)
|
||||||
(reg-sub :peers-count :peers-count)
|
(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?
|
(reg-sub :disconnected?
|
||||||
:<- [:peers-count]
|
:<- [:peers-count]
|
||||||
(fn [peers-count]
|
(fn [peers-count]
|
||||||
(zero? 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?
|
(reg-sub :syncing?
|
||||||
:<- [:sync-state]
|
:<- [:sync-state]
|
||||||
(fn [sync-state]
|
(fn [sync-state]
|
||||||
|
|
Loading…
Reference in New Issue