do not render not active screen

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2021-04-12 11:25:52 +02:00
parent 5eed7bd560
commit f6e480344d
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
3 changed files with 104 additions and 51 deletions

View File

@ -940,7 +940,7 @@
(empty? messages)))
(re-frame/reg-sub
:chats/chat-messages-stream
:chats/raw-chat-messages-stream
(fn [[_ chat-id] _]
[(re-frame/subscribe [:chats/message-list chat-id])
(re-frame/subscribe [:chats/chat-messages chat-id])
@ -955,13 +955,49 @@
(hydrate-messages messages)
(chat.db/add-gaps messages-gaps range all-loaded? public?))))
;;we want to keep data unchanged so react doesn't change component when we leave screen
(def memo-chat-messages-stream (atom nil))
(re-frame/reg-sub
:chats/chat-messages-stream
(fn [[_ chat-id] _]
[(re-frame/subscribe [:chats/raw-chat-messages-stream chat-id])
(re-frame/subscribe [:view-id])])
(fn [[messages view-id]]
(if (= view-id :chat)
(do
(reset! memo-chat-messages-stream messages)
messages)
@memo-chat-messages-stream)))
(def memo-profile-messages-stream (atom nil))
(re-frame/reg-sub
:chats/profile-messages-stream
(fn [[_ chat-id] _]
[(re-frame/subscribe [:chats/raw-chat-messages-stream chat-id])
(re-frame/subscribe [:view-id])])
(fn [[messages view-id]]
(if (= view-id :profile)
(do
(reset! memo-profile-messages-stream messages)
messages)
@memo-profile-messages-stream)))
(def memo-timeline-messages-stream (atom nil))
(re-frame/reg-sub
:chats/timeline-messages-stream
:<- [:chats/message-list constants/timeline-chat-id]
:<- [:chats/chat-messages constants/timeline-chat-id]
(fn [[message-list messages]]
(-> (models.message-list/->seq message-list)
(hydrate-messages messages))))
:<- [:view-id]
(fn [[message-list messages view-id]]
(if (= view-id :status)
(let [res (-> (models.message-list/->seq message-list)
(hydrate-messages messages))]
(reset! memo-timeline-messages-stream res)
res)
@memo-timeline-messages-stream)))
(re-frame/reg-sub
:chats/current-profile-chat
@ -1281,29 +1317,44 @@
(fn [[{:keys [:stickers/recent-stickers]} packs]]
(map (fn [hash] {:hash hash :pack (find-pack-id-for-hash hash packs)}) recent-stickers)))
;;HOME ==============================================================================================================
(def memo-home-items (atom nil))
(re-frame/reg-sub
:home-items
:<- [:search/home-filter]
:<- [:search/filtered-chats]
:<- [:communities/communities]
(fn [[search-filter filtered-chats communities]]
(let [communities-count (count communities)
chats-count (count filtered-chats)
;; If we have both communities & chats we want to display
;; a separator between them
:<- [:view-id]
(fn [[search-filter filtered-chats communities view-id]]
(if (= view-id :home)
(let [communities-count (count communities)
chats-count (count filtered-chats)
;; If we have both communities & chats we want to display
;; a separator between them
communities-with-separator (if (and (pos? communities-count)
(pos? chats-count))
(update communities
(dec communities-count)
assoc :last? true)
communities)]
{:search-filter search-filter
:items (concat communities-with-separator filtered-chats)})))
communities-with-separator (if (and (pos? communities-count)
(pos? chats-count))
(update communities
(dec communities-count)
assoc :last? true)
communities)
res {:search-filter search-filter
:items (concat communities-with-separator filtered-chats)}]
(reset! memo-home-items res)
res)
;;we want to keep data unchanged so react doesn't change component when we leave screen
@memo-home-items)))
(re-frame/reg-sub
:hide-home-tooltip?
:<- [:multiaccount]
(fn [multiaccount]
(:hide-home-tooltip? multiaccount)))
;;PAIRING ==============================================================================================================
(re-frame/reg-sub
:pairing/installations
:<- [:get-pairing-installations]
@ -1316,7 +1367,7 @@
(re-frame/reg-sub
:pairing/installation-id
:<- [:multiaccount]
:installation-id)
(fn [multiaccount] (:installation-id multiaccount)))
(re-frame/reg-sub
:pairing/installation-name

View File

@ -151,39 +151,41 @@
[inner-item/home-list-item home-item]
[communities.views/community-home-list-item home-item]))
(defn communities-and-chats [items loading? search-filter hide-home-tooltip?]
[:<>
[connectivity/loading-indicator]
(if loading?
[react/view {:flex 1 :align-items :center :justify-content :center}
[react/activity-indicator {:animating true}]]
(if (and (empty? items)
(empty? search-filter)
hide-home-tooltip?
(not @search-active?))
[welcome-blank-page]
[list/flat-list
{:key-fn #(or (:chat-id %) (:id %))
:keyboard-should-persist-taps :always
:data items
:render-fn render-fn
:header [:<>
(when (or (seq items) @search-active? (seq search-filter))
[search-input-wrapper search-filter items])
[referral-item/list-item]
(when (and (empty? items)
(or @search-active? (seq search-filter)))
[start-suggestion search-filter])]
:footer (if (and (not hide-home-tooltip?) (not @search-active?))
[home-tooltip-view]
[react/view {:height 68}])}]))])
(defn chat-list-key-fn [item]
(or (:chat-id item) (:id item)))
(views/defview communities-and-chats []
(views/letsubs [{:keys [items search-filter]} [:home-items]
hide-home-tooltip? [:hide-home-tooltip?]]
(if (and (empty? items)
(empty? search-filter)
hide-home-tooltip?
(not @search-active?))
[welcome-blank-page]
[list/flat-list
{:key-fn chat-list-key-fn
:keyboard-should-persist-taps :always
:data items
:render-fn render-fn
:header [:<>
(when (or (seq items) @search-active? (seq search-filter))
[search-input-wrapper search-filter items])
[referral-item/list-item]
(when (and (empty? items)
(or @search-active? (seq search-filter)))
[start-suggestion search-filter])]
:footer (if (and (not hide-home-tooltip?) (not @search-active?))
[home-tooltip-view]
[react/view {:height 68}])}])))
(views/defview chats-list []
(views/letsubs [loading? [:chats/loading?]
{:keys [items
search-filter]} [:home-items]
{:keys [hide-home-tooltip?]} [:multiaccount]]
[communities-and-chats items loading? search-filter hide-home-tooltip?]))
(views/letsubs [loading? [:chats/loading?]]
[:<>
[connectivity/loading-indicator]
(if loading?
[react/view {:flex 1 :align-items :center :justify-content :center}
[react/activity-indicator {:animating true}]]
[communities-and-chats])]))
(views/defview plus-button []
(views/letsubs [logging-in? [:multiaccounts/login]]

View File

@ -158,7 +158,7 @@
(defn profile []
(let [{:keys [public-key name ens-verified] :as contact} @(re-frame/subscribe [:contacts/current-contact])
current-chat-id @(re-frame/subscribe [:chats/current-profile-chat])
messages @(re-frame/subscribe [:chats/chat-messages-stream current-chat-id])
messages @(re-frame/subscribe [:chats/profile-messages-stream current-chat-id])
no-messages? @(re-frame/subscribe [:chats/chat-no-messages? current-chat-id])
muted? (:muted @(re-frame/subscribe [:chats/chat public-key]))
[first-name second-name] (multiaccounts/contact-two-names contact true)