Improve switcher cards lifecycle (#14751)

This commit is contained in:
Parvesh Monu 2023-01-12 02:37:55 +05:30 committed by GitHub
parent 220341e0be
commit 5c0bd33697
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 38 additions and 29 deletions

View File

@ -54,11 +54,13 @@
;; Helper functions
(defn get-shared-value
[anim]
(.-value anim))
(when anim
(.-value anim)))
(defn set-shared-value
[anim val]
(set! (.-value anim) val))
(when anim
(set! (.-value anim) val)))
(defn kebab-case->camelCase
[k]

View File

@ -220,11 +220,17 @@
(rf/defn close-chat
{:events [:close-chat]}
[{:keys [db] :as cofx}]
[{:keys [db] :as cofx} navigate-to-shell?]
(when-let [chat-id (:current-chat-id db)]
(chat.state/reset-visible-item)
(rf/merge cofx
{:db (dissoc db :current-chat-id)}
(merge
{:db (dissoc db :current-chat-id)}
(let [community-id (get-in db [:chats chat-id :community-id])]
;; When navigating back from community chat to community, update switcher card
(when (and community-id (not navigate-to-shell?))
{:dispatch [:shell/add-switcher-card
:community {:community-id community-id}]})))
(delete-for-me/sync-all)
(delete-message/send-all)
(offload-messages chat-id))))
@ -243,7 +249,8 @@
[{:keys [db now] :as cofx} chat-id]
(rf/merge cofx
{:clear-message-notifications
[[chat-id] (get-in db [:multiaccount :remote-push-notifications-enabled?])]}
[[chat-id] (get-in db [:multiaccount :remote-push-notifications-enabled?])]
:dispatch [:shell/close-switcher-card chat-id]}
(deactivate-chat chat-id)
(offload-messages chat-id)))
@ -268,7 +275,7 @@
(navigation/change-tab :chat)
(when-not (= (:view-id db) :community)
(navigation/pop-to-root-tab :chat-stack))
(close-chat)
(close-chat false)
(force-close-chat chat-id)
(fn [{:keys [db]}]
{:db (assoc db :current-chat-id chat-id)})
@ -284,7 +291,7 @@
{:dispatch [:navigate-to-nav2 :chat chat-id from-shell?]}
(when-not (= (:view-id db) :community)
(navigation/pop-to-root-tab :shell-stack))
(close-chat)
(close-chat false)
(force-close-chat chat-id)
(fn [{:keys [db]}]
{:db (assoc db :current-chat-id chat-id)})
@ -311,7 +318,7 @@
(assoc-in [:chats chat-id] chat)
:always
(update :chats-home-list conj chat-id))
:dispatch [:chat.ui/navigate-to-chat chat-id]}))
:dispatch [:chat.ui/navigate-to-chat-nav2 chat-id]}))
(rf/defn navigate-to-user-pinned-messages
"Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data"

View File

@ -187,6 +187,7 @@
(keys (get-in db [:communities community-id :chats])))]
{:clear-message-notifications [community-chat-ids
(get-in db [:multiaccount :remote-push-notifications-enabled?])]
:dispatch [:shell/close-switcher-card community-id]
:json-rpc/call [{:method "wakuext_leaveCommunity"
:params [community-id]
:js-response true

View File

@ -47,6 +47,7 @@
(update :chats dissoc public-key)
(update :chats-home-list disj public-key)
(assoc-in [:contacts/contacts public-key :added] false))
:dispatch [:shell/close-switcher-card public-key]
:clear-message-notifications
[[public-key] (get-in db [:multiaccount :remote-push-notifications-enabled?])]}
(activity-center/notifications-fetch-unread-count)

View File

@ -14,7 +14,7 @@
{:events [:navigate-chat-updated]}
[cofx chat-id]
(when (get-in cofx [:db :chats chat-id])
(models.chat/navigate-to-chat cofx chat-id)))
(models.chat/navigate-to-chat-nav2 cofx chat-id nil)))
(rf/defn handle-chat-removed
{:events [:chat-removed]}
@ -71,7 +71,7 @@
(rf/defn create-from-link
[cofx {:keys [chat-id invitation-admin chat-name]}]
(if (get-in cofx [:db :chats chat-id])
{:dispatch [:chat.ui/navigate-to-chat chat-id]}
{:dispatch [:chat.ui/navigate-to-chat-nav2 chat-id]}
{:json-rpc/call [{:method "wakuext_createGroupChatFromInvitation"
:params [chat-name chat-id invitation-admin]
:js-response true

View File

@ -251,7 +251,7 @@
(rf/dispatch-sync [:chat.ui/start-chat chat-id]) ;; start a new chat
(rf-test/wait-for
[:status-im.chat.models/one-to-one-chat-created]
(rf/dispatch-sync [:chat.ui/navigate-to-chat chat-id])
(rf/dispatch-sync [:chat.ui/navigate-to-chat-nav2 chat-id])
(is (= chat-id @(rf/subscribe [:chats/current-chat-id])))
(logout!)
(rf-test/wait-for [::logout/logout-method] ; we need to logout to make sure the node is not in
@ -276,7 +276,7 @@
(rf/dispatch-sync [:chat.ui/start-chat chat-id]) ;; start a new chat
(rf-test/wait-for
[:status-im.chat.models/one-to-one-chat-created]
(rf/dispatch-sync [:chat.ui/navigate-to-chat chat-id])
(rf/dispatch-sync [:chat.ui/navigate-to-chat-nav2 chat-id])
(is (= chat-id @(rf/subscribe [:chats/current-chat-id])))
(is @(rf/subscribe [:chats/chat chat-id]))
(rf/dispatch-sync [:chat.ui/remove-chat-pressed chat-id])
@ -307,7 +307,7 @@
(rf/dispatch-sync [:chat.ui/start-chat chat-id]) ;; start a new chat
(rf-test/wait-for
[:status-im.chat.models/one-to-one-chat-created]
(rf/dispatch-sync [:chat.ui/navigate-to-chat chat-id])
(rf/dispatch-sync [:chat.ui/navigate-to-chat-nav2 chat-id])
(is (= chat-id @(rf/subscribe [:chats/current-chat-id])))
(is @(rf/subscribe [:chats/chat chat-id]))
(rf/dispatch-sync [::chat.models/mute-chat-toggled chat-id true])

View File

@ -424,7 +424,7 @@
:key-uid
(fn [stored-key-uid]
(when (= stored-key-uid key-uid)
(re-frame/dispatch [:chat.ui/navigate-to-chat chat-id])))))))))
(re-frame/dispatch [:chat.ui/navigate-to-chat-nav2 chat-id])))))))))
(rf/defn check-last-chat
{:events [::check-last-chat]}

View File

@ -48,7 +48,7 @@
:on-press (fn []
(rf/dispatch [:communities/load-category-states id])
(rf/dispatch [:dismiss-keyboard])
(rf/dispatch [:navigate-to :community {:community-id id}]))
(rf/dispatch [:navigate-to-nav2 :community {:community-id id}]))
:on-long-press #(rf/dispatch [:bottom-sheet/show-sheet
{:content (fn []
[community/community-actions community])}])}
@ -111,7 +111,7 @@
(i18n/label :t/open-membership))]]
:on-press #(do
(rf/dispatch [:dismiss-keyboard])
(rf/dispatch [:navigate-to :community {:community-id id}]))}]))
(rf/dispatch [:navigate-to-nav2 :community {:community-id id}]))}]))
(defn communities-actions
[]

View File

@ -27,7 +27,6 @@
[status-im.ui.screens.home.styles :as styles]
[status-im.ui.screens.home.views.inner-item :as inner-item]
[status-im.utils.utils :as utils]
[status-im2.setup.config :as config]
[utils.debounce :as debounce])
(:require-macros [status-im.utils.views :as views]))
@ -152,9 +151,7 @@
home-item
{:on-press (fn []
(re-frame/dispatch [:dismiss-keyboard])
(if config/new-ui-enabled?
(re-frame/dispatch [:chat.ui/navigate-to-chat-nav2 chat-id])
(re-frame/dispatch [:chat.ui/navigate-to-chat chat-id]))
(re-frame/dispatch [:chat.ui/navigate-to-chat-nav2 chat-id])
(re-frame/dispatch [:search/home-filter-changed nil]))
:on-long-press #(re-frame/dispatch [:bottom-sheet/show-sheet
{:content (fn []
@ -169,9 +166,7 @@
home-item
{:on-press (fn []
(re-frame/dispatch [:dismiss-keyboard])
(if config/new-ui-enabled?
(re-frame/dispatch [:chat.ui/navigate-to-chat-nav2 chat-id])
(re-frame/dispatch [:chat.ui/navigate-to-chat chat-id]))
(re-frame/dispatch [:chat.ui/navigate-to-chat-nav2 chat-id])
(re-frame/dispatch [:search/home-filter-changed nil]))
:on-long-press #(re-frame/dispatch [:bottom-sheet/show-sheet
{:content (fn []

View File

@ -96,7 +96,7 @@
(rf/defn handle-community-chat
[cofx {:keys [chat-id]}]
(log/info "universal-links: handling community chat" chat-id)
{:dispatch [:chat.ui/navigate-to-chat chat-id]})
{:dispatch [:chat.ui/navigate-to-chat-nav2 chat-id]})
(rf/defn handle-public-chat
[cofx {:keys [topic]}]

View File

@ -46,7 +46,7 @@
[rn/touchable-opacity
{:on-press (fn []
(rf/dispatch [:hide-popover])
(rf/dispatch [:chat.ui/navigate-to-chat chat-id]))}
(rf/dispatch [:chat.ui/navigate-to-chat-nav2 chat-id]))}
[quo/activity-log
{:title (i18n/label :t/mention)
:icon :i/mention

View File

@ -38,7 +38,7 @@
[rn/touchable-opacity
{:on-press (fn []
(rf/dispatch [:hide-popover])
(rf/dispatch [:chat.ui/navigate-to-chat chat-id]))}
(rf/dispatch [:chat.ui/navigate-to-chat-nav2 chat-id]))}
[quo/activity-log
{:title (i18n/label :t/message-reply)
:icon :i/reply

View File

@ -181,7 +181,7 @@
[quo/floating-shell-button
(merge {:jump-to
{:on-press #(do
(rf/dispatch [:close-chat])
(rf/dispatch [:close-chat true])
(rf/dispatch [:shell/navigate-to-jump-to]))
:label (i18n/label :t/jump-to)}}
(when @show-floating-scroll-down-button

View File

@ -19,7 +19,10 @@
(when (and (not @navigation.state/curr-modal) (= (get @re-frame.db/app-db :view-id) :chat))
(rn/hw-back-remove-listener navigate-back-handler)
(rf/dispatch [:close-chat])
(rf/dispatch [:navigate-back])))
(rf/dispatch [:navigate-back])
;; If true is not returned back button event will bubble up,
;; and will call system back button action
true))
(defn page-nav
[]

View File

@ -102,7 +102,7 @@
{:content {:community-channel {:emoji (:emoji channel)
:channel-name (str "# " (:name channel))}}
:on-press (fn []
(re-frame/dispatch [:navigate-to :community {:community-id community-id}])
(re-frame/dispatch [:navigate-to-nav2 :community {:community-id community-id}])
(js/setTimeout
#(re-frame/dispatch [:chat.ui/navigate-to-chat-nav2 channel-id true])
100))}))