Fix Activity Center popover not opening (#15239)

Fixes #15230 - The popover state in the app db must be discarded before trying to
open the Activity Center. This workaround is used in other parts of the app too.
It's ugly, but the only quick fix I found.

It's plenty obvious the popover component and all its surrounding logic should
be revisited in the future.
This commit is contained in:
Icaro Motta 2023-03-03 10:34:55 -03:00 committed by GitHub
parent 8923408972
commit 064204256e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 33 deletions

View File

@ -25,19 +25,25 @@
(rf/defn open-activity-center (rf/defn open-activity-center
{:events [:activity-center/open]} {:events [:activity-center/open]}
[{:keys [db]} {:keys [filter-type filter-status]}] [{:keys [db]} {:keys [filter-type filter-status]}]
{:db (cond-> db ;; It's essential to clean-up the popover state and delay the dispatch of the
filter-status ;; `:show-popover` event, otherwise the popover won't be displayed under
(assoc-in [:activity-center :filter :status] filter-status) ;; certain conditions. See issue
;; https://github.com/status-im/status-mobile/issues/15230
{:db (cond-> (dissoc db :popover/popover)
filter-status
(assoc-in [:activity-center :filter :status] filter-status)
filter-type filter-type
(assoc-in [:activity-center :filter :type] filter-type)) (assoc-in [:activity-center :filter :type] filter-type))
:dispatch [:show-popover :dispatch-later [{:ms 25
{:view :activity-center :dispatch [:show-popover
:style {:margin 0} {:view :activity-center
:disable-touchable-overlay? true :style {:margin 0}
:blur-view? true :disable-touchable-overlay? true
:blur-view-props {:blur-amount 20 :delay-ms 225
:blur-type :dark}}]}) :blur-view? true
:blur-view-props {:blur-amount 20
:blur-type :dark}}]}]})
;;;; Misc ;;;; Misc

View File

@ -36,32 +36,23 @@
(deftest open-activity-center-test (deftest open-activity-center-test
(testing "opens the activity center with filters enabled" (testing "opens the activity center with filters enabled"
(h/run-test-sync (h/run-test-sync
(let [spy-queue (atom [])] (setup)
(setup) (rf/dispatch [:activity-center/open
(h/spy-fx spy-queue :show-popover) {:filter-type types/contact-request
:filter-status :unread}])
(rf/dispatch [:activity-center/open (is (= {:status :unread
{:filter-type types/contact-request :type types/contact-request}
:filter-status :unread}]) (get-in (h/db) [:activity-center :filter])))))
(is (= {:status :unread (testing "opens the activity center with default filters"
:type types/contact-request}
(get-in (h/db) [:activity-center :filter])))
(is (= [{:id :show-popover :args nil}]
@spy-queue)))))
(testing "opens the activity center without custom filters"
(h/run-test-sync (h/run-test-sync
(let [spy-queue (atom [])] (setup)
(setup)
(h/spy-fx spy-queue :show-popover)
(rf/dispatch [:activity-center/open]) (rf/dispatch [:activity-center/open])
(is (= {:status :unread :type types/no-type} (is (= {:status :unread :type types/no-type}
(get-in (h/db) [:activity-center :filter]))) (get-in (h/db) [:activity-center :filter]))))))
(is (= [{:id :show-popover :args nil}]
@spy-queue))))))
(deftest mark-as-read-test (deftest mark-as-read-test
(testing "does nothing if the notification ID cannot be found in the app db" (testing "does nothing if the notification ID cannot be found in the app db"