Don't allow multiple pop ups to be shown

This commit makes sure that we don't display multiple pop ups when
mailserver connection has failed.
It also fixes the navigation to avoid being stuck on Profile tab.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2020-12-01 13:37:01 +01:00
parent 7e069ed342
commit b9f896f4e3
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
3 changed files with 31 additions and 17 deletions

View File

@ -518,6 +518,30 @@
(connect-to-mailserver) (connect-to-mailserver)
(disconnect-from-mailserver)))) (disconnect-from-mailserver))))
(defonce showing-connection-error-popup? (atom false))
(defn show-connection-error! [db current-fleet preferred-mailserver]
(reset! showing-connection-error-popup? true)
(assoc db :ui/show-confirmation
{:title (i18n/label :t/mailserver-error-title)
:content (i18n/label :t/mailserver-error-content)
:confirm-button-text (i18n/label :t/mailserver-pick-another)
:on-cancel #(do
(reset! showing-connection-error-popup? false)
(re-frame/dispatch [:mailserver.ui/dismiss-connection-error true]))
:on-accept #(do
(reset! showing-connection-error-popup? false)
(re-frame/dispatch [:mailserver.ui/dismiss-connection-error true])
(re-frame/dispatch [:navigate-to :profile-stack {:screen :offline-messaging-settings}]))
:extra-options [{:text (i18n/label :t/mailserver-retry)
:onPress #(do
(reset! showing-connection-error-popup? false)
(re-frame/dispatch
[:mailserver.ui/connect-confirmed
current-fleet
preferred-mailserver]))
:style "default"}]}))
(fx/defn change-mailserver (fx/defn change-mailserver
"mark mailserver status as `:error` if custom mailserver is used "mark mailserver status as `:error` if custom mailserver is used
otherwise try to reconnect to another mailserver" otherwise try to reconnect to another mailserver"
@ -532,22 +556,9 @@
(let [error-dismissed? (connection-error-dismissed db) (let [error-dismissed? (connection-error-dismissed db)
current-fleet (node/current-fleet-key db)] current-fleet (node/current-fleet-key db)]
;; Error connecting to the mail server ;; Error connecting to the mail server
{:db (cond-> {:db (update-mailserver-state db :error)}
(update-mailserver-state db :error) (not (or error-dismissed? @showing-connection-error-popup?))
:ui/show-confirmation (show-connection-error! current-fleet preferred-mailserver)))
(when-not error-dismissed?
{:title (i18n/label :t/mailserver-error-title)
:content (i18n/label :t/mailserver-error-content)
:confirm-button-text (i18n/label :t/mailserver-pick-another)
:on-cancel #(re-frame/dispatch [:mailserver.ui/dismiss-connection-error true])
:on-accept #(re-frame/dispatch
[:navigate-to :offline-messaging-settings])
:extra-options [{:text (i18n/label :t/mailserver-retry)
:onPress #(re-frame/dispatch
[:mailserver.ui/connect-confirmed
current-fleet
preferred-mailserver])
:style "default"}]})})
(let [{:keys [address]} (fetch-current db)] (let [{:keys [address]} (fetch-current db)]
(fx/merge cofx (fx/merge cofx
{:mailserver/remove-peer address} {:mailserver/remove-peer address}

View File

@ -53,6 +53,8 @@
[react/view {:style styles/wrapper} [react/view {:style styles/wrapper}
[topbar/topbar [topbar/topbar
{:title (i18n/label :t/history-nodes) {:title (i18n/label :t/history-nodes)
;; Navigate to profile as we might be coming from home to this view
:navigation {:on-press #(re-frame/dispatch [:navigate-to :profile-stack {:screen :sync-settings}])}
:right-accessories :right-accessories
[{:icon :main-icons/add-circle [{:icon :main-icons/add-circle
:on-press #(re-frame/dispatch [:mailserver.ui/add-pressed])}]}] :on-press #(re-frame/dispatch [:mailserver.ui/add-pressed])}]}]

View File

@ -14,7 +14,8 @@
current-fleet [:fleets/current-fleet] current-fleet [:fleets/current-fleet]
mailservers [:mailserver/mailservers]] mailservers [:mailserver/mailservers]]
[react/view {:style {:flex 1 :background-color colors/white}} [react/view {:style {:flex 1 :background-color colors/white}}
[topbar/topbar {:title (i18n/label :t/sync-settings)}] [topbar/topbar {:title (i18n/label :t/sync-settings)
:navigation {:on-press #(re-frame/dispatch [:navigate-to :profile-stack {:screen :my-profile}])}}]
[react/scroll-view [react/scroll-view
[quo/list-header (i18n/label :t/data-syncing)] [quo/list-header (i18n/label :t/data-syncing)]
[quo/list-item {:size :small [quo/list-item {:size :small