fix: duplicate sub key :communities/fetching-community (#18890)

This commit is contained in:
yqrashawn 2024-03-14 09:50:06 +08:00 committed by GitHub
parent e26d3a856d
commit 614b03d701
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 44 additions and 21 deletions

View File

@ -293,7 +293,7 @@
(defn community-fetched (defn community-fetched
[{:keys [db]} [community-id community]] [{:keys [db]} [community-id community]]
(when community (when community
{:db (update db :communities/fetching-community dissoc community-id) {:db (update db :communities/fetching-communities dissoc community-id)
:fx [[:dispatch [:communities/handle-community community]] :fx [[:dispatch [:communities/handle-community community]]
[:dispatch [:communities/update-last-opened-at community-id]] [:dispatch [:communities/update-last-opened-at community-id]]
[:dispatch [:dispatch
@ -304,14 +304,14 @@
(defn community-failed-to-fetch (defn community-failed-to-fetch
[{:keys [db]} [community-id]] [{:keys [db]} [community-id]]
{:db (update db :communities/fetching-community dissoc community-id)}) {:db (update db :communities/fetching-communities dissoc community-id)})
(rf/reg-event-fx :chat.ui/community-failed-to-fetch community-failed-to-fetch) (rf/reg-event-fx :chat.ui/community-failed-to-fetch community-failed-to-fetch)
(defn fetch-community (defn fetch-community
[{:keys [db]} [{:keys [community-id update-last-opened-at?]}]] [{:keys [db]} [{:keys [community-id update-last-opened-at?]}]]
(when (and community-id (not (get-in db [:communities/fetching-community community-id]))) (when (and community-id (not (get-in db [:communities/fetching-communities community-id])))
{:db (assoc-in db [:communities/fetching-community community-id] true) {:db (assoc-in db [:communities/fetching-communities community-id] true)
:json-rpc/call [{:method "wakuext_fetchCommunity" :json-rpc/call [{:method "wakuext_fetchCommunity"
:params [{:CommunityKey community-id :params [{:CommunityKey community-id
:TryDatabase true :TryDatabase true
@ -398,7 +398,7 @@
:community-id community-id})}}) :community-id community-id})}})
(rf/reg-event-fx :communities/navigate-to-community-overview (rf/reg-event-fx :communities/navigate-to-community-overview
(fn [cofx [deserialized-key]] (fn [{:keys [db] :as cofx} [deserialized-key]]
(if (string/starts-with? deserialized-key constants/serialization-key) (if (string/starts-with? deserialized-key constants/serialization-key)
(navigate-to-serialized-community cofx deserialized-key) (navigate-to-serialized-community cofx deserialized-key)
(rf/merge (rf/merge
@ -407,7 +407,9 @@
[:communities/fetch-community [:communities/fetch-community
{:community-id deserialized-key {:community-id deserialized-key
:update-last-opened-at? true}]] :update-last-opened-at? true}]]
[:dispatch [:navigate-to :community-overview deserialized-key]]]} [:dispatch [:navigate-to :community-overview deserialized-key]]
(when (get-in db [:communities deserialized-key :joined])
[:dispatch [:activity-center.notifications/dismiss-community-overview deserialized-key]])]}
(navigation/pop-to-root :shell-stack))))) (navigation/pop-to-root :shell-stack)))))
(rf/reg-event-fx :communities/navigate-to-community-chat (rf/reg-event-fx :communities/navigate-to-community-chat

View File

@ -104,7 +104,7 @@
(testing "with community id" (testing "with community id"
(testing "update fetching indicator in db" (testing "update fetching indicator in db"
(is (match? (is (match?
{:db {:communities/fetching-community {community-id true}}} {:db {:communities/fetching-communities {community-id true}}}
(events/fetch-community {} [{:community-id community-id}])))) (events/fetch-community {} [{:community-id community-id}]))))
(testing "call the fetch community rpc method with correct community id" (testing "call the fetch community rpc method with correct community id"
(is (match? (is (match?
@ -124,21 +124,21 @@
(testing "remove community id from fetching indicator in db" (testing "remove community id from fetching indicator in db"
(is (match? (is (match?
nil nil
(get-in (events/community-failed-to-fetch {:db {:communities/fetching-community (get-in (events/community-failed-to-fetch {:db {:communities/fetching-communities
{community-id true}}} {community-id true}}}
[community-id]) [community-id])
[:db :communities/fetching-community community-id])))))) [:db :communities/fetching-communities community-id]))))))
(deftest community-fetched (deftest community-fetched
(with-redefs [link-preview.events/community-link (fn [id] (str "community-link+" id))] (with-redefs [link-preview.events/community-link (fn [id] (str "community-link+" id))]
(testing "given a community" (testing "given a community"
(let [cofx {:db {:communities/fetching-community {community-id true}}} (let [cofx {:db {:communities/fetching-communities {community-id true}}}
arg [community-id {:id community-id}]] arg [community-id {:id community-id}]]
(testing "remove community id from fetching indicator in db" (testing "remove community id from fetching indicator in db"
(is (match? (is (match?
nil nil
(get-in (events/community-fetched cofx arg) (get-in (events/community-fetched cofx arg)
[:db :communities/fetching-community community-id])))) [:db :communities/fetching-communities community-id]))))
(testing "dispatch fxs" (testing "dispatch fxs"
(is (match? (is (match?
{:fx [[:dispatch [:communities/handle-community {:id community-id}]] {:fx [[:dispatch [:communities/handle-community {:id community-id}]]
@ -148,7 +148,7 @@
{:id community-id}]]]} {:id community-id}]]]}
(events/community-fetched cofx arg)))))) (events/community-fetched cofx arg))))))
(testing "given a joined community" (testing "given a joined community"
(let [cofx {:db {:communities/fetching-community {community-id true}}} (let [cofx {:db {:communities/fetching-communities {community-id true}}}
arg [community-id {:id community-id :joined true}]] arg [community-id {:id community-id :joined true}]]
(testing "dispatch fxs, do not spectate community" (testing "dispatch fxs, do not spectate community"
(is (match? (is (match?
@ -159,7 +159,7 @@
{:id community-id}]]]} {:id community-id}]]]}
(events/community-fetched cofx arg)))))) (events/community-fetched cofx arg))))))
(testing "given a token-gated community" (testing "given a token-gated community"
(let [cofx {:db {:communities/fetching-community {community-id true}}} (let [cofx {:db {:communities/fetching-communities {community-id true}}}
arg [community-id {:id community-id :tokenPermissions [1]}]] arg [community-id {:id community-id :tokenPermissions [1]}]]
(testing "dispatch fxs, do not spectate community" (testing "dispatch fxs, do not spectate community"
(is (match? (is (match?

View File

@ -21,6 +21,13 @@
:align-items :center :align-items :center
:margin-top 20}) :margin-top 20})
(def fetching-placeholder
{:align-items :center
:justify-content :center
:flex 1})
(def fetching-text {:color :red})
(def blur-channel-header (def blur-channel-header
{:position :absolute {:position :absolute
:top 100 :top 100

View File

@ -7,6 +7,7 @@
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent] [reagent.core :as reagent]
[status-im.common.home.actions.view :as actions] [status-im.common.home.actions.view :as actions]
[status-im.common.not-implemented :as not-implemented]
[status-im.common.scroll-page.style :as scroll-page.style] [status-im.common.scroll-page.style :as scroll-page.style]
[status-im.common.scroll-page.view :as scroll-page] [status-im.common.scroll-page.view :as scroll-page]
[status-im.config :as config] [status-im.config :as config]
@ -177,7 +178,6 @@
:icon-left (if can-request-access? :i/unlocked :i/locked)} :icon-left (if can-request-access? :i/unlocked :i/locked)}
(i18n/label :t/join-open-community)]]))) (i18n/label :t/join-open-community)]])))
(defn- join-community (defn- join-community
[{:keys [id joined permissions role-permissions? can-join?] :as community}] [{:keys [id joined permissions role-permissions? can-join?] :as community}]
(let [pending? (rf/sub [:communities/my-pending-request-to-join id]) (let [pending? (rf/sub [:communities/my-pending-request-to-join id])
@ -366,14 +366,28 @@
;; might have been removed. ;; might have been removed.
on-first-channel-height-changed}]])))) on-first-channel-height-changed}]]))))
(defn- community-fetching-placeholder
[id]
(let [fetching? (rf/sub [:communities/fetching-community id])]
[rn/view
{:style style/fetching-placeholder
:accessibility-label (if fetching?
:fetching-community-overview
:failed-to-fetch-community-overview)}
[not-implemented/not-implemented
[rn/text
{:style style/fetching-text}
(if fetching?
"Fetching community..."
"Failed to fetch community")]]]))
(defn- community-card-page-view (defn- community-card-page-view
[id] [id]
(let [{:keys [id joined name images] (let [{:keys [joined name images]
:as community} (rf/sub [:communities/community id])] :as community} (rf/sub [:communities/community id])]
(when community (if community
(when joined [community-scroll-page id joined name images]
(rf/dispatch [:activity-center.notifications/dismiss-community-overview id])) [community-fetching-placeholder id])))
[community-scroll-page id joined name images])))
(defn view (defn view
[id] [id]

View File

@ -9,7 +9,7 @@
(re-frame/reg-sub (re-frame/reg-sub
:communities/fetching-community :communities/fetching-community
:<- [:communities/fetching-community] :<- [:communities/fetching-communities]
(fn [info [_ id]] (fn [info [_ id]]
(get info id))) (get info id)))

View File

@ -143,7 +143,7 @@
(reg-root-key-sub :communities/create-channel :communities/create-channel) (reg-root-key-sub :communities/create-channel :communities/create-channel)
(reg-root-key-sub :communities/requests-to-join :communities/requests-to-join) (reg-root-key-sub :communities/requests-to-join :communities/requests-to-join)
(reg-root-key-sub :communities/community-id-input :communities/community-id-input) (reg-root-key-sub :communities/community-id-input :communities/community-id-input)
(reg-root-key-sub :communities/fetching-community :communities/fetching-community) (reg-root-key-sub :communities/fetching-communities :communities/fetching-communities)
(reg-root-key-sub :communities/my-pending-requests-to-join :communities/my-pending-requests-to-join) (reg-root-key-sub :communities/my-pending-requests-to-join :communities/my-pending-requests-to-join)
(reg-root-key-sub :communities/collapsed-categories :communities/collapsed-categories) (reg-root-key-sub :communities/collapsed-categories :communities/collapsed-categories)
(reg-root-key-sub :communities/selected-tab :communities/selected-tab) (reg-root-key-sub :communities/selected-tab :communities/selected-tab)