Feature: add "close community" action to opened/spectated communities (#21687)

This change adds a new action to the action-drawer for opened communities. Now opened communities can be closed by users by pressing on the "Close community" action. Note, that this action will only be available to communities displayed in communities list under the opened tab.
This commit is contained in:
Sean Hagstrom 2024-12-06 09:50:40 -08:00 committed by GitHub
parent f75fff9dd8
commit 10101a23e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 51 additions and 24 deletions

View File

@ -130,4 +130,12 @@
:role-permissions? true} :role-permissions? true}
:profile/test-networks-enabled? false}) :profile/test-networks-enabled? false})
(h/render [options/community-options-bottom-sheet {:id "test"}]) (h/render [options/community-options-bottom-sheet {:id "test"}])
(h/is-truthy (h/get-by-translation-text :t/unmute-community)))) (h/is-truthy (h/get-by-translation-text :t/unmute-community)))
(h/test "opened community"
(h/setup-subs {:communities/my-pending-request-to-join nil
:communities/community {:joined false
:spectated true}
:profile/test-networks-enabled? false})
(h/render [options/community-options-bottom-sheet {:id "test"}])
(h/is-truthy (h/get-by-translation-text :t/close-community))))

View File

@ -124,6 +124,14 @@
:on-press #(rf/dispatch [:show-bottom-sheet :on-press #(rf/dispatch [:show-bottom-sheet
{:content (fn [] [leave-menu/leave-sheet id color])}])}) {:content (fn [] [leave-menu/leave-sheet id color])}])})
(defn close-community
[id]
{:icon :i/close-circle
:label (i18n/label :t/close-community)
:accessibility-label :close-community
:danger? true
:on-press #(rf/dispatch [:communities/leave id])})
(defn cancel-request-to-join (defn cancel-request-to-join
[id request-id] [id request-id]
{:icon :i/block {:icon :i/block
@ -135,7 +143,7 @@
request-id])}])}) request-id])}])})
(defn not-joined-options (defn not-joined-options
[id token-gated? intro-message test-networks-enabled?] [{:keys [id join-pending? spectated? token-gated? intro-message test-networks-enabled?]}]
(let [common [(show-qr id) (share-community id)] (let [common [(show-qr id) (share-community id)]
specific (cond specific (cond
(and token-gated? (not test-networks-enabled?)) (and token-gated? (not test-networks-enabled?))
@ -146,19 +154,22 @@
(not token-gated?) (not token-gated?)
[(view-members id) (view-rules id intro-message) (invite-contacts id)])] [(view-members id) (view-rules id intro-message) (invite-contacts id)])]
[(concat specific common)])) [(concat specific
common
(when (and spectated? (not join-pending?))
[(assoc (close-community id) :add-divider? true)]))]))
(defn join-request-sent-options (defn join-request-sent-options
[id token-gated? request-id intro-message test-networks-enabled?] [{:keys [id request-id] :as config}]
[(conj (first (not-joined-options id token-gated? intro-message test-networks-enabled?)) [(conj (first (not-joined-options config))
(assoc (cancel-request-to-join id request-id) :add-divider? true))]) (assoc (cancel-request-to-join id request-id) :add-divider? true))])
(defn banned-options (defn banned-options
[id token-gated? intro-message test-networks-enabled?] [config]
(not-joined-options id token-gated? intro-message test-networks-enabled?)) (not-joined-options config))
(defn joined-options (defn joined-options
[id token-gated? muted? muted-till color intro-message] [{:keys [id token-gated? muted? muted-till color intro-message]}]
[[(view-members id) [[(view-members id)
(view-rules id intro-message) (view-rules id intro-message)
(when token-gated? (view-token-gating id)) (when token-gated? (view-token-gating id))
@ -173,7 +184,7 @@
[(assoc (leave-community id color) :add-divider? true)]]) [(assoc (leave-community id color) :add-divider? true)]])
(defn owner-options (defn owner-options
[id token-gated? muted? muted-till intro-message] [{:keys [id token-gated? muted? muted-till intro-message]}]
[[(view-members id) [[(view-members id)
(view-rules id intro-message) (view-rules id intro-message)
(when token-gated? (view-token-gating id)) (when token-gated? (view-token-gating id))
@ -186,22 +197,29 @@
(defn get-context-drawers (defn get-context-drawers
[{:keys [id]}] [{:keys [id]}]
(let [{:keys [role-permissions? admin joined (let [{:keys
muted banList muted-till color [id admin joined
banList color muted muted-till
spectated role-permissions?
intro-message]} (rf/sub [:communities/community id]) intro-message]} (rf/sub [:communities/community id])
request-id (rf/sub [:communities/my-pending-request-to-join id]) request-id (rf/sub [:communities/my-pending-request-to-join id])
test-networks? (rf/sub [:profile/test-networks-enabled?])] test-networks? (rf/sub [:profile/test-networks-enabled?])
config {:id id
:color color
:muted-till muted-till
:muted? muted
:spectated? spectated
:token-gated? role-permissions?
:intro-message intro-message
:test-networks? test-networks?
:join-pending? (boolean request-id)
:request-id request-id}]
(cond (cond
admin admin (owner-options config)
(owner-options id role-permissions? muted muted-till intro-message) joined (joined-options config)
joined request-id (join-request-sent-options config)
(joined-options id role-permissions? muted muted-till color intro-message) banList (banned-options config)
request-id :else (not-joined-options config))))
(join-request-sent-options id role-permissions? request-id intro-message test-networks?)
banList
(banned-options id role-permissions? intro-message test-networks?)
:else
(not-joined-options id role-permissions? intro-message test-networks?))))
(defn community-options-bottom-sheet (defn community-options-bottom-sheet
[id] [id]

View File

@ -395,6 +395,7 @@
"close-app-title": "Warning!", "close-app-title": "Warning!",
"close-chat": "Close chat", "close-chat": "Close chat",
"close-chat-confirmation": "This conversation will disappear from the list.\nIt will appear again if the contact sends a new message.", "close-chat-confirmation": "This conversation will disappear from the list.\nIt will appear again if the contact sends a new message.",
"close-community": "Close community",
"close-contact-search": "Close contact search", "close-contact-search": "Close contact search",
"code-snippet": "Code snippet", "code-snippet": "Code snippet",
"collectibles": "Collectibles", "collectibles": "Collectibles",