Communities now correctly listed in pending/joined sections. (#14515)

This commit is contained in:
Volodymyr Kozieiev 2022-12-13 20:55:32 +00:00 committed by GitHub
parent 5693df5a74
commit 68ea7cdfc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 163 additions and 90 deletions

View File

@ -46,20 +46,25 @@
:render-fn render-fn}]) :render-fn render-fn}])
(defn segments-community-lists [selected-tab] (defn segments-community-lists [selected-tab]
(let [communities (rf/sub [:communities/community-ids]) (let [ids-by-user-involvement (rf/sub [:communities/community-ids-by-user-involvement])
tab @selected-tab] tab @selected-tab]
[rn/view {:style {:padding-left 20 [rn/view {:style {:padding-left 20
:padding-right 8 :padding-right 8
:padding-vertical 12}} :padding-vertical 12}}
(case tab (case tab
:joined :joined
[communities-list communities] [communities-list (:joined ids-by-user-involvement)]
:pending :pending
[communities-list communities] [communities-list (:pending ids-by-user-involvement)]
:opened :opened
[communities-list communities])])) [communities-list (:opened ids-by-user-involvement)]
[quo/information-box
{:type :error
:icon :i/info}
(i18n/label :t/error)])]))
(defn home [] (defn home []
(let [selected-tab (reagent/atom :joined)] (let [selected-tab (reagent/atom :joined)]

View File

@ -1,17 +1,20 @@
(ns status-im2.contexts.communities.overview.style (ns status-im2.contexts.communities.overview.style
(:require [react-native.platform :as platform] (:require [react-native.platform :as platform]))
[quo2.foundations.colors :as colors]))
(def preview-user (def preview-user
{:flex-direction :row {:flex-direction :row
:align-items :center :align-items :center
:margin-top 20}) :margin-top 20})
(def blur-channel-header {:blur-amount 32 (def blur-channel-header
:blur-type :xlight {:position :absolute
:overlay-color (if platform/ios? colors/white-opa-70 :transparent) :top (if platform/ios? 56 60)
:style {:position :absolute :height 34
:top (if platform/ios? 56 60) :width "100%"
:height 34 :flex 1})
:width "100%"
:flex 1}}) (def join-button
{:width "100%"
:margin-top 20
:margin-left :auto
:margin-right :auto})

View File

@ -44,38 +44,38 @@
#(rf/dispatch #(rf/dispatch
[:bottom-sheet/show-sheet [:bottom-sheet/show-sheet
{:content {:content
(constantly [quo/token-gating (fn [] [quo/token-gating
{:channel {:name name {:channel {:name name
:community-color (colors/custom-color :pink 50) :community-color (colors/custom-color :pink 50)
:emoji emoji :emoji emoji
:emoji-background-color channel-color :emoji-background-color channel-color
:on-enter-channel (fn [] (utils/show-popup "Entered channel" "Wuhuu!! You successfully entered the channel :)")) :on-enter-channel (fn [] (utils/show-popup "Entered channel" "Wuhuu!! You successfully entered the channel :)"))
:gates {:read [{:token "KNC" :gates {:read [{:token "KNC"
:token-img-src knc-token-img :token-img-src knc-token-img
:amount 200 :amount 200
:is-sufficient? true} :is-sufficient? true}
{:token "MANA" {:token "MANA"
:token-img-src mana-token-img :token-img-src mana-token-img
:amount 10 :amount 10
:is-sufficient? false :is-sufficient? false
:is-purchasable true} :is-purchasable true}
{:token "RARE" {:token "RARE"
:token-img-src rare-token-img :token-img-src rare-token-img
:amount 10 :amount 10
:is-sufficient? false}] :is-sufficient? false}]
:write [{:token "KNC" :write [{:token "KNC"
:token-img-src knc-token-img :token-img-src knc-token-img
:amount 200 :amount 200
:is-sufficient? true} :is-sufficient? true}
{:token "DAI" {:token "DAI"
:token-img-src dai-token-img :token-img-src dai-token-img
:amount 20 :amount 20
:is-purchasable true :is-purchasable true
:is-sufficient? false} :is-sufficient? false}
{:token "ETH" {:token "ETH"
:token-img-src eth-token-img :token-img-src eth-token-img
:amount 0.5 :amount 0.5
:is-sufficient? false}]}}}]) :is-sufficient? false}]}}}])
:content-height 210}])) :content-height 210}]))
(def mock-list-of-channels {:Welcome [{:name "welcome" (def mock-list-of-channels {:Welcome [{:name "welcome"
@ -159,8 +159,27 @@
(def channel-list-component (memoize channel-list-component-fn)) (def channel-list-component (memoize channel-list-component-fn))
(defn join-community [{:keys [joined can-join? requested-to-join-at community-color] :as community}]
(let [node-offline? (and can-join? (not joined) (pos? requested-to-join-at))]
[:<>
(when-not joined
[quo/button
{:on-press #(rf/dispatch [:bottom-sheet/show-sheet
{:content (fn [] [requests.actions/request-to-join community])
:content-height 300}])
:override-background-color community-color
:style style/join-button
:before :i/communities}
(i18n/label :t/join-open-community)])
(when node-offline?
[quo/information-box
{:type :informative
:icon :i/info
:style {:margin-top 12}}
(i18n/label :t/request-processed-after-node-online)])]))
(defn render-page-content [{:keys [name description locked joined id images (defn render-page-content [{:keys [name description locked joined id images
status tokens tags community-color] status tokens tags]
:as community} :as community}
channel-heights first-channel-height] channel-heights first-channel-height]
(let [thumbnail-image (get-in images [:thumbnail])] (let [thumbnail-image (get-in images [:thumbnail])]
@ -192,27 +211,27 @@
[:bottom-sheet/show-sheet [:bottom-sheet/show-sheet
{:content-height 210 {:content-height 210
:content :content
(constantly [quo/token-gating (fn [] [quo/token-gating
{:community {:name name {:community {:name name
:community-color colors/primary-50 :community-color colors/primary-50
:community-avatar (cond :community-avatar (cond
(= id constants/status-community-id) (= id constants/status-community-id)
(resources/get-image :status-logo) (resources/get-image :status-logo)
(seq thumbnail-image) (seq thumbnail-image)
thumbnail-image) thumbnail-image)
:gates {:join [{:token "KNC" :gates {:join [{:token "KNC"
:token-img-src knc-token-img :token-img-src knc-token-img
:amount 200 :amount 200
:is-sufficient? true} :is-sufficient? true}
{:token "MANA" {:token "MANA"
:token-img-src mana-token-img :token-img-src mana-token-img
:amount 10 :amount 10
:is-sufficient? false :is-sufficient? false
:is-purchasable true} :is-purchasable true}
{:token "RARE" {:token "RARE"
:token-img-src rare-token-img :token-img-src rare-token-img
:amount 10 :amount 10
:is-sufficient? false}]}}}])}])}]]) :is-sufficient? false}]}}}])}])}]])
(when joined (when joined
[rn/view {:position :absolute [rn/view {:position :absolute
:top 12 :top 12
@ -238,25 +257,17 @@
[rn/view {:margin-top 12}] [rn/view {:margin-top 12}]
[quo/community-tags tags] [quo/community-tags tags]
[preview-user-list] [preview-user-list]
(when-not joined [join-community community]]
[quo/button
{:on-press #(rf/dispatch [:bottom-sheet/show-sheet
{:content (constantly [requests.actions/request-to-join community])
:content-height 300}])
:override-background-color community-color
:style
{:width "100%"
:margin-top 20
:margin-left :auto
:margin-right :auto}
:before :i/communities}
(i18n/label :t/join-open-community)])]
[channel-list-component channel-heights first-channel-height]]))) [channel-list-component channel-heights first-channel-height]])))
(defn render-sticky-header [channel-heights first-channel-height] (defn render-sticky-header [channel-heights first-channel-height]
(fn [scroll-height] (fn [scroll-height]
(when (> scroll-height @first-channel-height) (when (> scroll-height @first-channel-height)
[rn/blur-view style/blur-channel-header [rn/blur-view
{:blur-amount 32
:blur-type :xlight
:overlay-color (if platform/ios? colors/white-opa-70 :transparent)
:style style/blur-channel-header}
[quo/divider-label [quo/divider-label
{:label (:label (last (filter (fn [{:keys [height]}] {:label (:label (last (filter (fn [{:keys [height]}]
(>= scroll-height (+ height @first-channel-height))) (>= scroll-height (+ height @first-channel-height)))
@ -274,7 +285,7 @@
{:icon :i/options {:icon :i/options
:background-color (scroll-page/icon-color) :background-color (scroll-page/icon-color)
:on-press #(rf/dispatch [:bottom-sheet/show-sheet :on-press #(rf/dispatch [:bottom-sheet/show-sheet
{:content (constantly [home.actions/actions community]) {:content (fn [] [home.actions/actions community])
:content-height 400}])}]} :content-height 400}])}]}
name)] name)]
(fn [] (fn []
@ -288,7 +299,6 @@
(defn overview [] (defn overview []
(let [community-mock (rf/sub [:get-screen-params :community-overview]) ;TODO stop using mock data and only pass community id (let [community-mock (rf/sub [:get-screen-params :community-overview]) ;TODO stop using mock data and only pass community id
community (rf/sub [:communities/community (:id community-mock)])] community (rf/sub [:communities/community (:id community-mock)])]
[rn/view {:style [rn/view {:style
{:position :absolute {:position :absolute
:top (if platform/ios? 0 44) :top (if platform/ios? 0 44)

View File

@ -91,12 +91,12 @@
:<- [:communities] :<- [:communities]
(fn [[communities-enabled? search-filter communities]] (fn [[communities-enabled? search-filter communities]]
(filterv (filterv
(fn [{:keys [name joined id]}] (fn [{:keys [name id]}]
(and joined (and
(or communities-enabled? (or communities-enabled?
(= id constants/status-community-id)) (= id constants/status-community-id))
(or (empty? search-filter) (or (empty? search-filter)
(string/includes? (string/lower-case (str name)) search-filter)))) (string/includes? (string/lower-case (str name)) search-filter))))
(vals communities)))) (vals communities))))
(re-frame/reg-sub (re-frame/reg-sub
@ -105,6 +105,25 @@
(fn [communities] (fn [communities]
(map :id communities))) (map :id communities)))
(re-frame/reg-sub
:communities/community-ids-by-user-involvement
:<- [:communities/communities]
;; Return communities splitted by level of user participation. Some communities user
;; already joined, to some of them join request sent and others were opened one day
;; and their data remained in app-db.
;; Result map has form: {:joined [id1, id2] :pending [id3, id5] :opened [id4]}"
(fn [communities]
(reduce (fn [acc community]
(let [joined? (:joined community)
requested? (pos? (:requested-to-join-at community))
id (:id community)]
(cond
joined? (update acc :joined conj id)
requested? (update acc :pending conj id)
:else (update acc :opened conj id))))
{:joined [] :pending [] :opened []}
communities)))
(defn community->home-item [community counts] (defn community->home-item [community counts]
{:name (:name community) {:name (:name community)
:muted? (:muted community) :muted? (:muted community)

View File

@ -74,3 +74,38 @@
(is (= {:unviewed-messages-count 0 (is (= {:unviewed-messages-count 0
:unviewed-mentions-count 0} :unviewed-mentions-count 0}
(rf/sub [sub-name community-id]))))) (rf/sub [sub-name community-id])))))
(h/deftest-sub :communities/community-ids-by-user-involvement
[sub-name]
(testing "Empty communities list"
(swap! rf-db/app-db assoc :communities
{})
(is (= {:joined [], :pending [], :opened []}
(rf/sub [sub-name]))))
(testing "Only opened communities"
(swap! rf-db/app-db assoc
:communities/enabled? true
:communities
{"0x1" {:id "0x1" :name "civilized monkeys"}
"0x2" {:id "0x2" :name "Civilized rats"}
"0x3" {:id "0x3" :name "Civilized dolphins"}})
(is (= {:joined [], :pending [], :opened ["0x1" "0x2" "0x3"]}
(rf/sub [sub-name]))))
(testing "One joined community and two opened ones"
(swap! rf-db/app-db assoc
:communities/enabled? true
:communities
{"0x1" {:id "0x1" :name "civilized monkeys" :joined true}
"0x2" {:id "0x2" :name "Civilized rats"}
"0x3" {:id "0x3" :name "Civilized dolphins"}})
(is (= {:joined ["0x1"], :pending [], :opened ["0x2" "0x3"]}
(rf/sub [sub-name]))))
(testing "One joined community, one open and one pending"
(swap! rf-db/app-db assoc
:communities/enabled? true
:communities
{"0x1" {:id "0x1" :name "civilized monkeys" :joined true}
"0x2" {:id "0x2" :name "Civilized rats" :requested-to-join-at 1000}
"0x3" {:id "0x3" :name "Civilized dolphins"}})
(is (= {:joined ["0x1"], :pending ["0x2"], :opened ["0x3"]}
(rf/sub [sub-name])))))

View File

@ -1123,6 +1123,7 @@
"repeat-pin": "Repeat new 6-digit passcode", "repeat-pin": "Repeat new 6-digit passcode",
"repeat-puk": "Repeat new 12-digit PUK", "repeat-puk": "Repeat new 12-digit PUK",
"report-bug-email-template": "1. Issue Description\n{{description}}\n\n\n2. Steps to reproduce\n{{steps}}\n\n\n3. Attach screenshots that can demo the problem, please\n", "report-bug-email-template": "1. Issue Description\n{{description}}\n\n\n2. Steps to reproduce\n{{steps}}\n\n\n3. Attach screenshots that can demo the problem, please\n",
"request-processed-after-node-online": "Your request will be processed once the community owner node is back online.",
"request-transaction": "Request transaction", "request-transaction": "Request transaction",
"required-field": "Required field", "required-field": "Required field",
"resend-message": "Resend", "resend-message": "Resend",