do not render not active screen
Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
parent
5eed7bd560
commit
f6e480344d
|
@ -940,7 +940,7 @@
|
||||||
(empty? messages)))
|
(empty? messages)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:chats/chat-messages-stream
|
:chats/raw-chat-messages-stream
|
||||||
(fn [[_ chat-id] _]
|
(fn [[_ chat-id] _]
|
||||||
[(re-frame/subscribe [:chats/message-list chat-id])
|
[(re-frame/subscribe [:chats/message-list chat-id])
|
||||||
(re-frame/subscribe [:chats/chat-messages chat-id])
|
(re-frame/subscribe [:chats/chat-messages chat-id])
|
||||||
|
@ -955,13 +955,49 @@
|
||||||
(hydrate-messages messages)
|
(hydrate-messages messages)
|
||||||
(chat.db/add-gaps messages-gaps range all-loaded? public?))))
|
(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
|
(re-frame/reg-sub
|
||||||
:chats/timeline-messages-stream
|
:chats/timeline-messages-stream
|
||||||
:<- [:chats/message-list constants/timeline-chat-id]
|
:<- [:chats/message-list constants/timeline-chat-id]
|
||||||
:<- [:chats/chat-messages constants/timeline-chat-id]
|
:<- [:chats/chat-messages constants/timeline-chat-id]
|
||||||
(fn [[message-list messages]]
|
:<- [:view-id]
|
||||||
(-> (models.message-list/->seq message-list)
|
(fn [[message-list messages view-id]]
|
||||||
(hydrate-messages messages))))
|
(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
|
(re-frame/reg-sub
|
||||||
:chats/current-profile-chat
|
:chats/current-profile-chat
|
||||||
|
@ -1281,12 +1317,18 @@
|
||||||
(fn [[{:keys [:stickers/recent-stickers]} packs]]
|
(fn [[{:keys [:stickers/recent-stickers]} packs]]
|
||||||
(map (fn [hash] {:hash hash :pack (find-pack-id-for-hash hash packs)}) recent-stickers)))
|
(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
|
(re-frame/reg-sub
|
||||||
:home-items
|
:home-items
|
||||||
:<- [:search/home-filter]
|
:<- [:search/home-filter]
|
||||||
:<- [:search/filtered-chats]
|
:<- [:search/filtered-chats]
|
||||||
:<- [:communities/communities]
|
:<- [:communities/communities]
|
||||||
(fn [[search-filter filtered-chats communities]]
|
:<- [:view-id]
|
||||||
|
(fn [[search-filter filtered-chats communities view-id]]
|
||||||
|
(if (= view-id :home)
|
||||||
(let [communities-count (count communities)
|
(let [communities-count (count communities)
|
||||||
chats-count (count filtered-chats)
|
chats-count (count filtered-chats)
|
||||||
;; If we have both communities & chats we want to display
|
;; If we have both communities & chats we want to display
|
||||||
|
@ -1297,13 +1339,22 @@
|
||||||
(update communities
|
(update communities
|
||||||
(dec communities-count)
|
(dec communities-count)
|
||||||
assoc :last? true)
|
assoc :last? true)
|
||||||
communities)]
|
communities)
|
||||||
{:search-filter search-filter
|
res {:search-filter search-filter
|
||||||
:items (concat communities-with-separator filtered-chats)})))
|
: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 ==============================================================================================================
|
;;PAIRING ==============================================================================================================
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:pairing/installations
|
:pairing/installations
|
||||||
:<- [:get-pairing-installations]
|
:<- [:get-pairing-installations]
|
||||||
|
@ -1316,7 +1367,7 @@
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:pairing/installation-id
|
:pairing/installation-id
|
||||||
:<- [:multiaccount]
|
:<- [:multiaccount]
|
||||||
:installation-id)
|
(fn [multiaccount] (:installation-id multiaccount)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:pairing/installation-name
|
:pairing/installation-name
|
||||||
|
|
|
@ -151,19 +151,19 @@
|
||||||
[inner-item/home-list-item home-item]
|
[inner-item/home-list-item home-item]
|
||||||
[communities.views/community-home-list-item home-item]))
|
[communities.views/community-home-list-item home-item]))
|
||||||
|
|
||||||
(defn communities-and-chats [items loading? search-filter hide-home-tooltip?]
|
(defn chat-list-key-fn [item]
|
||||||
[:<>
|
(or (:chat-id item) (:id item)))
|
||||||
[connectivity/loading-indicator]
|
|
||||||
(if loading?
|
(views/defview communities-and-chats []
|
||||||
[react/view {:flex 1 :align-items :center :justify-content :center}
|
(views/letsubs [{:keys [items search-filter]} [:home-items]
|
||||||
[react/activity-indicator {:animating true}]]
|
hide-home-tooltip? [:hide-home-tooltip?]]
|
||||||
(if (and (empty? items)
|
(if (and (empty? items)
|
||||||
(empty? search-filter)
|
(empty? search-filter)
|
||||||
hide-home-tooltip?
|
hide-home-tooltip?
|
||||||
(not @search-active?))
|
(not @search-active?))
|
||||||
[welcome-blank-page]
|
[welcome-blank-page]
|
||||||
[list/flat-list
|
[list/flat-list
|
||||||
{:key-fn #(or (:chat-id %) (:id %))
|
{:key-fn chat-list-key-fn
|
||||||
:keyboard-should-persist-taps :always
|
:keyboard-should-persist-taps :always
|
||||||
:data items
|
:data items
|
||||||
:render-fn render-fn
|
:render-fn render-fn
|
||||||
|
@ -176,14 +176,16 @@
|
||||||
[start-suggestion search-filter])]
|
[start-suggestion search-filter])]
|
||||||
:footer (if (and (not hide-home-tooltip?) (not @search-active?))
|
:footer (if (and (not hide-home-tooltip?) (not @search-active?))
|
||||||
[home-tooltip-view]
|
[home-tooltip-view]
|
||||||
[react/view {:height 68}])}]))])
|
[react/view {:height 68}])}])))
|
||||||
|
|
||||||
(views/defview chats-list []
|
(views/defview chats-list []
|
||||||
(views/letsubs [loading? [:chats/loading?]
|
(views/letsubs [loading? [:chats/loading?]]
|
||||||
{:keys [items
|
[:<>
|
||||||
search-filter]} [:home-items]
|
[connectivity/loading-indicator]
|
||||||
{:keys [hide-home-tooltip?]} [:multiaccount]]
|
(if loading?
|
||||||
[communities-and-chats items loading? search-filter hide-home-tooltip?]))
|
[react/view {:flex 1 :align-items :center :justify-content :center}
|
||||||
|
[react/activity-indicator {:animating true}]]
|
||||||
|
[communities-and-chats])]))
|
||||||
|
|
||||||
(views/defview plus-button []
|
(views/defview plus-button []
|
||||||
(views/letsubs [logging-in? [:multiaccounts/login]]
|
(views/letsubs [logging-in? [:multiaccounts/login]]
|
||||||
|
|
|
@ -158,7 +158,7 @@
|
||||||
(defn profile []
|
(defn profile []
|
||||||
(let [{:keys [public-key name ens-verified] :as contact} @(re-frame/subscribe [:contacts/current-contact])
|
(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])
|
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])
|
no-messages? @(re-frame/subscribe [:chats/chat-no-messages? current-chat-id])
|
||||||
muted? (:muted @(re-frame/subscribe [:chats/chat public-key]))
|
muted? (:muted @(re-frame/subscribe [:chats/chat public-key]))
|
||||||
[first-name second-name] (multiaccounts/contact-two-names contact true)
|
[first-name second-name] (multiaccounts/contact-two-names contact true)
|
||||||
|
|
Loading…
Reference in New Issue