Disable button when request is in flight

This commit is contained in:
Andrea Maria Piana 2024-03-26 13:17:15 +00:00
parent 7de1f95054
commit 98deaa4459
No known key found for this signature in database
6 changed files with 170 additions and 114 deletions

View File

@ -64,6 +64,7 @@
:canJoin :can-join?
:requestedToJoinAt :requested-to-join-at
:isMember :is-member?
:outroMessage :outro-message
:adminSettings :admin-settings
:tokenPermissions :token-permissions
:communityTokensMetadata :tokens-metadata

View File

@ -195,41 +195,23 @@
:button-type :grey
:on-button-press open-permission-sheet))])]))
(defn view
[]
(let [{id :community-id} (rf/sub [:get-screen-params])
{:keys [color joined] outro-message :outroMessage} (rf/sub [:communities/community id])
highest-role (rf/sub [:communities/highest-role-for-selection id])
[unmodified-role _] (rn/use-state highest-role)
can-edit-addresses? (rf/sub [:communities/can-edit-shared-addresses? id])
pending? (boolean (rf/sub [:communities/my-pending-request-to-join id]))
wallet-accounts (rf/sub [:wallet/accounts-without-watched-accounts])
unmodified-addresses-to-reveal (rf/sub [:communities/addresses-to-reveal id])
[addresses-to-reveal set-addresses-to-reveal] (rn/use-state unmodified-addresses-to-reveal)
unmodified-flag-share-all-addresses (rf/sub [:communities/share-all-addresses? id])
[flag-share-all-addresses
set-flag-share-all-addresses] (rn/use-state unmodified-flag-share-all-addresses)
identical-choices? (and (= unmodified-addresses-to-reveal addresses-to-reveal)
(= unmodified-flag-share-all-addresses flag-share-all-addresses))
toggle-flag-share-all-addresses
(fn []
(let [new-value (not flag-share-all-addresses)]
(set-flag-share-all-addresses new-value)
(when new-value
(set-addresses-to-reveal (set (map :address wallet-accounts))))))
(defn selection-bottom-actions
[id
{:keys [flag-share-all-addresses
addresses-to-reveal
cancel-selection
can-edit-addresses?
identical-choices?]}]
(let [color (rf/sub [:communities/community-color id])
outro-message (rf/sub [:communities/community-outro-message id])
joined (rf/sub [:communities/community-joined id])
checking? (rf/sub [:communities/permissions-check-for-selection-checking? id])
cancel-join-request
(rn/use-callback
(fn []
(rf/dispatch [:show-bottom-sheet
{:content (fn [] [cancel-join-request-drawer id])}])))
leave-community
(rn/use-callback
(fn []
@ -237,14 +219,6 @@
{:content (fn [] [leave-community-drawer id outro-message])}]))
[outro-message])
cancel-selection
(fn []
(rf/dispatch [:communities/check-permissions-to-join-community
id
unmodified-addresses-to-reveal
:based-on-client-selection])
(rf/dispatch [:hide-bottom-sheet]))
confirm-changes
(fn []
(if can-edit-addresses?
@ -263,7 +237,107 @@
(rf/dispatch [:hide-bottom-sheet]))}]))}])
(do
(rf/dispatch [:communities/set-share-all-addresses id flag-share-all-addresses])
(rf/dispatch [:communities/set-addresses-to-reveal id addresses-to-reveal]))))]
(rf/dispatch [:communities/set-addresses-to-reveal id addresses-to-reveal]))))
pending? (rf/sub [:communities/has-pending-request-to-join? id])
highest-role (rf/sub [:communities/highest-role-for-selection id])
[unmodified-role _] (rn/use-state highest-role)]
[quo/bottom-actions
(cond-> {:role (role-keyword highest-role)
:description (if highest-role
:top
:top-error)
:button-one-props {:customization-color color
:on-press confirm-changes
:disabled? (or checking?
(empty? addresses-to-reveal)
(not highest-role)
identical-choices?)}}
can-edit-addresses?
(->
(assoc :actions :one-action
:button-one-label (cond
(and pending? (not highest-role))
(i18n/label :t/cancel-request)
(and joined (not highest-role))
(i18n/label :t/leave-community)
:else
(i18n/label :t/confirm-changes))
:description-top-text (cond
(and pending? highest-role)
(i18n/label :t/eligible-to-join-as)
(and joined (= highest-role unmodified-role))
(i18n/label :t/you-are-a)
(and joined (not= highest-role unmodified-role))
(i18n/label :t/you-will-be-a))
:error-message (cond
(and pending? (not highest-role))
(i18n/label :t/community-join-requirements-not-met)
(and joined (not highest-role))
(i18n/label :t/membership-requirements-not-met)))
(update :button-one-props
merge
(cond (and pending? (not highest-role))
{:type :danger
:disabled? false
:on-press cancel-join-request}
(and joined (not highest-role))
{:type :danger
:disabled? false
:on-press leave-community})))
(not can-edit-addresses?)
(assoc :actions :two-actions
:button-one-label (i18n/label :t/confirm-changes)
:button-two-label (i18n/label :t/cancel)
:button-two-props {:type :grey
:on-press cancel-selection}
:error-message (cond
(empty? addresses-to-reveal)
(i18n/label :t/no-addresses-selected)
(not highest-role)
(i18n/label :t/addresses-dont-contain-tokens-needed))))]))
(defn view
[]
(let [{id :community-id} (rf/sub [:get-screen-params])
color (rf/sub [:communities/community-color id])
can-edit-addresses? (rf/sub [:communities/can-edit-shared-addresses? id])
wallet-accounts (rf/sub [:wallet/accounts-without-watched-accounts])
unmodified-addresses-to-reveal (rf/sub [:communities/addresses-to-reveal id])
[addresses-to-reveal set-addresses-to-reveal] (rn/use-state unmodified-addresses-to-reveal)
unmodified-flag-share-all-addresses (rf/sub [:communities/share-all-addresses? id])
[flag-share-all-addresses
set-flag-share-all-addresses] (rn/use-state unmodified-flag-share-all-addresses)
identical-choices? (and (= unmodified-addresses-to-reveal addresses-to-reveal)
(= unmodified-flag-share-all-addresses flag-share-all-addresses))
cancel-selection
(fn []
(rf/dispatch [:communities/check-permissions-to-join-community
id
unmodified-addresses-to-reveal
:based-on-client-selection])
(rf/dispatch [:hide-bottom-sheet]))
toggle-flag-share-all-addresses
(fn []
(let [new-value (not flag-share-all-addresses)]
(set-flag-share-all-addresses new-value)
(when new-value
(set-addresses-to-reveal (set (map :address wallet-accounts))))))]
(rn/use-mount
(fn []
@ -274,7 +348,6 @@
(fn []
(rf/dispatch [:communities/check-permissions-to-join-during-selection id addresses-to-reveal]))
[id addresses-to-reveal])
[:<>
[page-top
{:community-id id
@ -299,64 +372,14 @@
:key-fn :address
:data wallet-accounts}]
[quo/bottom-actions
(cond-> {:role (role-keyword highest-role)
:description (if highest-role
:top
:top-error)
:button-one-props {:customization-color color
:on-press confirm-changes
:disabled? (or (empty? addresses-to-reveal)
(not highest-role)
identical-choices?)}}
can-edit-addresses?
(->
(assoc :actions :one-action
:button-one-label (cond
(and pending? (not highest-role))
(i18n/label :t/cancel-request)
(and joined (not highest-role))
(i18n/label :t/leave-community)
:else
(i18n/label :t/confirm-changes))
:description-top-text (cond
(and pending? highest-role)
(i18n/label :t/eligible-to-join-as)
(and joined (= highest-role unmodified-role))
(i18n/label :t/you-are-a)
(and joined (not= highest-role unmodified-role))
(i18n/label :t/you-will-be-a))
:error-message (cond
(and pending? (not highest-role))
(i18n/label :t/community-join-requirements-not-met)
(and joined (not highest-role))
(i18n/label :t/membership-requirements-not-met)))
(update :button-one-props
merge
(cond (and pending? (not highest-role))
{:type :danger
:disabled? false
:on-press cancel-join-request}
(and joined (not highest-role))
{:type :danger
:disabled? false
:on-press leave-community})))
(not can-edit-addresses?)
(assoc :actions :two-actions
:button-one-label (i18n/label :t/confirm-changes)
:button-two-label (i18n/label :t/cancel)
:button-two-props {:type :grey
:on-press cancel-selection}
:error-message (cond
(empty? addresses-to-reveal)
(i18n/label :t/no-addresses-selected)
(not highest-role)
(i18n/label :t/addresses-dont-contain-tokens-needed))))]]))
[selection-bottom-actions id
{:flag-share-all-addresses
flag-share-all-addresses
:addresses-to-reveal
addresses-to-reveal
:cancel-selection
cancel-selection
:can-edit-addresses?
can-edit-addresses?
:identical-choices?
identical-choices?}]]))

View File

@ -3,7 +3,7 @@
[taoensso.timbre :as log]
[utils.re-frame :as rf]))
(def commmunity-keys-renamed
(def community-keys-renamed
{:requestedAccessAt :requested-access-at
:fileSize :file-size
:communityTokensMetadata :community-tokens-metadata
@ -35,7 +35,7 @@
[k]
(let [s (name k)
starts-with-digit? (re-matches #"^\d.*" s)
existing-rename (k commmunity-keys-renamed)]
existing-rename (k community-keys-renamed)]
(cond starts-with-digit? s
existing-rename existing-rename
:else (keyword s))))

View File

@ -32,21 +32,38 @@
(re-frame/reg-sub
:communities/community-chats
:<- [:communities]
(fn [communities [_ id]]
(get-in communities [id :chats])))
(fn [[_ community-id]]
[(re-frame/subscribe [:communities/community community-id])])
(fn [[{:keys [chats]}] _]
chats))
(re-frame/reg-sub
:communities/community-color
:<- [:communities]
(fn [communities [_ id]]
(get-in communities [id :color])))
(fn [[_ community-id]]
[(re-frame/subscribe [:communities/community community-id])])
(fn [[{:keys [color]}] _]
color))
(re-frame/reg-sub
:communities/community-outro-message
(fn [[_ community-id]]
[(re-frame/subscribe [:communities/community community-id])])
(fn [[{:keys [outro-message]}] _]
outro-message))
(re-frame/reg-sub
:communities/community-joined
(fn [[_ community-id]]
[(re-frame/subscribe [:communities/community community-id])])
(fn [[{:keys [joined]}] _]
joined))
(re-frame/reg-sub
:communities/community-members
:<- [:communities]
(fn [communities [_ id]]
(get-in communities [id :members])))
(fn [[_ community-id]]
[(re-frame/subscribe [:communities/community community-id])])
(fn [[{:keys [members]}] _]
members))
(re-frame/reg-sub
:communities/current-community-members
@ -160,6 +177,13 @@
(fn [requests [_ community-id]]
(:id (get requests community-id))))
(re-frame/reg-sub
:communities/has-pending-request-to-join?
(fn [[_ community-id]]
(re-frame/subscribe [:communities/my-pending-request-to-join community-id]))
(fn [request]
(boolean request)))
(re-frame/reg-sub
:communities/edited-community
:<- [:communities]
@ -329,6 +353,7 @@
(fn [permissions [_ id]]
(get permissions id)))
(re-frame/reg-sub
:communities/checking-permissions-all-by-id
:<- [:communities/permissions-check-all]

View File

@ -345,7 +345,7 @@
:members {"0x04" {"roles" [1]}}}}
:members {"0x04" {"roles" [1]}}
:can-request-access? false
:outroMessage "bla"
:outro-message "bla"
:verified false}]
(swap! rf-db/app-db assoc-in [:communities community-id] community)
(swap! rf-db/app-db assoc-in [:communities/permissions-check community-id] checks)
@ -439,7 +439,7 @@
:token-images {"ETH" token-image-eth}
:name "Community super name"
:can-request-access? false
:outroMessage "bla"
:outro-message "bla"
:verified false}]
(swap! rf-db/app-db assoc-in [:communities community-id] community)
(swap! rf-db/app-db assoc-in [:communities/permissions-check-all community-id] checks)
@ -475,7 +475,7 @@
:token-images {"ETH" token-image-eth}
:name "Community super name"
:can-request-access? false
:outroMessage "bla"
:outro-message "bla"
:verified false}]
(swap! rf-db/app-db assoc-in [:communities community-id] community)
(swap! rf-db/app-db assoc-in [:communities/permissions-check-all community-id] checks)

View File

@ -40,6 +40,13 @@
(fn [permissions [_ id]]
(get permissions id)))
(re-frame/reg-sub
:communities/permissions-check-for-selection-checking?
(fn [[_ community-id]]
(re-frame/subscribe [:communities/permissions-check-for-selection community-id]))
(fn [check]
(:checking? check)))
(re-frame/reg-sub :communities/highest-role-for-selection
(fn [[_ community-id]]
[(re-frame/subscribe [:communities/permissions-check-for-selection community-id])])