use community subs correctly for performance

This commit is contained in:
Icaro Motta 2024-06-21 16:45:54 -03:00
parent 731ccdf2e5
commit b353dc6f1f
No known key found for this signature in database
GPG Key ID: 009557D9D014DF07
5 changed files with 47 additions and 27 deletions

View File

@ -69,9 +69,8 @@
[{:keys [notification set-swipeable-height customization-color] :as props}]
(let [{:keys [author community-id id membership-status
read timestamp]} notification
community (rf/sub [:communities/community community-id])
community-name (:name community)
community-image (get-in community [:images :thumbnail :uri])]
community-name (rf/sub [:communities/name community-id])
community-logo (rf/sub [:communities/logo community-id])]
[swipeable props
[quo/activity-log
{:title (i18n/label :t/join-request)
@ -86,7 +85,7 @@
{:type :community
:size 24
:blur? true
:community-logo community-image
:community-logo community-logo
:community-name community-name}]]
:items (condp = membership-status
constants/activity-center-membership-status-accepted

View File

@ -23,16 +23,13 @@
child])
(defn- get-header-text-and-context
[community membership-status]
(let [community-name (:name community)
permissions (:permissions community)
open? (not= 3 (:access permissions))
community-image (get-in community [:images :thumbnail :uri])
[community-logo community-name community-permissions membership-status]
(let [open? (not= 3 (:access community-permissions))
community-context-tag [quo/context-tag
{:type :community
:size 24
:blur? true
:community-logo community-image
:community-logo community-logo
:community-name community-name}]]
(cond
(= membership-status constants/activity-center-membership-status-idle)
@ -63,16 +60,21 @@
(defn view
[{:keys [notification set-swipeable-height customization-color] :as props}]
(let [{:keys [community-id membership-status read
timestamp]} notification
community (rf/sub [:communities/community community-id])
timestamp]} notification
community-name (rf/sub [:communities/name community-id])
community-logo (rf/sub [:communities/logo community-id])
community-permissions (rf/sub [:communities/permissions community-id])
{:keys [header-text
context]} (get-header-text-and-context community
membership-status)
on-press (rn/use-callback
(fn []
(rf/dispatch [:navigate-back])
(rf/dispatch [:communities/navigate-to-community-overview community-id]))
[community-id])]
context]} (get-header-text-and-context community-logo
community-name
community-permissions
membership-status)
on-press (rn/use-callback
(fn []
(rf/dispatch [:navigate-back])
(rf/dispatch [:communities/navigate-to-community-overview
community-id]))
[community-id])]
[swipeable props
[gesture/touchable-without-feedback {:on-press on-press}
[quo/activity-log

View File

@ -46,9 +46,8 @@
(let [{:keys [author chat-name community-id chat-id
message read timestamp]} notification
community-chat? (not (string/blank? community-id))
community (rf/sub [:communities/community community-id])
community-name (:name community)
community-image (get-in community [:images :thumbnail :uri])]
community-name (rf/sub [:communities/name community-id])
community-logo (rf/sub [:communities/logo community-id])]
[swipeable props
[gesture/touchable-without-feedback
{:on-press (fn []
@ -69,7 +68,7 @@
{:type :channel
:blur? true
:size 24
:community-logo community-image
:community-logo community-logo
:community-name community-name
:channel-name chat-name}]
[quo/context-tag

View File

@ -68,9 +68,8 @@
message read timestamp
album-messages]} notification
community-chat? (not (string/blank? community-id))
community (rf/sub [:communities/community community-id])
community-name (:name community)
community-image (get-in community [:images :thumbnail :uri])
community-name (rf/sub [:communities/name community-id])
community-logo (rf/sub [:communities/logo community-id])
media-server-port (rf/sub [:mediaserver/port])]
[swipeable props
[gesture/touchable-without-feedback
@ -91,7 +90,7 @@
{:type :channel
:blur? true
:size 24
:community-logo community-image
:community-logo community-logo
:community-name community-name
:channel-name chat-name}]
[quo/context-tag

View File

@ -15,12 +15,33 @@
(fn [info [_ id]]
(get info id)))
;; Do not use this subscription directly in views. There is a significant risk
;; of re-rendering views too frequently because an active community can change
;; for numerous reasons.
(re-frame/reg-sub
:communities/community
:<- [:communities]
(fn [communities [_ id]]
(get communities id)))
(re-frame/reg-sub :communities/logo
(fn [[_ community-id]]
[(re-frame/subscribe [:communities/community community-id])])
(fn [[community]]
(get-in community [:images :thumbnail :uri])))
(re-frame/reg-sub :communities/name
(fn [[_ community-id]]
[(re-frame/subscribe [:communities/community community-id])])
(fn [[{:keys [name]}]]
name))
(re-frame/reg-sub :communities/permissions
(fn [[_ community-id]]
[(re-frame/subscribe [:communities/community community-id])])
(fn [[{:keys [permissions]}]]
permissions))
(re-frame/reg-sub
:communities/community-color
(fn [[_ community-id]]