fix: handle limit event (#19066)
This commit is contained in:
parent
bccf0f8d11
commit
58606dc87c
|
@ -49,20 +49,41 @@
|
||||||
(rf/dispatch [:open-modal :new-contact]))}
|
(rf/dispatch [:open-modal :new-contact]))}
|
||||||
(i18n/label :t/add-a-contact)]]))
|
(i18n/label :t/add-a-contact)]]))
|
||||||
|
|
||||||
|
(def ^:private contacts-selection-limit (dec constants/max-group-chat-participants))
|
||||||
|
|
||||||
|
(defn- toggle-selection
|
||||||
|
[public-key user-selected?]
|
||||||
|
(let [selected-contacts-count (rf/sub [:selected-contacts-count])]
|
||||||
|
(if user-selected?
|
||||||
|
(re-frame/dispatch [:deselect-contact public-key])
|
||||||
|
(if (= contacts-selection-limit
|
||||||
|
selected-contacts-count)
|
||||||
|
(do
|
||||||
|
(rf/dispatch
|
||||||
|
[:toasts/upsert
|
||||||
|
{:id :remove-nickname
|
||||||
|
:type :negative
|
||||||
|
:text (i18n/label :t/new-group-limit
|
||||||
|
{:max-contacts
|
||||||
|
contacts-selection-limit})}])
|
||||||
|
true)
|
||||||
|
(re-frame/dispatch [:select-contact public-key])))))
|
||||||
|
|
||||||
(defn contact-item-render
|
(defn contact-item-render
|
||||||
[_]
|
[{:keys [public-key] :as item} set-has-error]
|
||||||
(fn [{:keys [public-key] :as item}]
|
(let [user-selected? (rf/sub [:is-contact-selected? public-key])
|
||||||
(let [user-selected? (rf/sub [:is-contact-selected? public-key])
|
on-toggle (fn []
|
||||||
on-toggle #(if user-selected?
|
(-> public-key
|
||||||
(re-frame/dispatch [:deselect-contact public-key])
|
(toggle-selection user-selected?)
|
||||||
(re-frame/dispatch [:select-contact public-key]))]
|
boolean
|
||||||
[contact-list-item/contact-list-item
|
set-has-error))]
|
||||||
{:on-press on-toggle
|
[contact-list-item/contact-list-item
|
||||||
:allow-multiple-presses? true
|
{:on-press on-toggle
|
||||||
:accessory {:type :checkbox
|
:allow-multiple-presses? true
|
||||||
:checked? user-selected?
|
:accessory {:type :checkbox
|
||||||
:on-check on-toggle}}
|
:checked? user-selected?
|
||||||
item])))
|
:on-check on-toggle}}
|
||||||
|
item]))
|
||||||
|
|
||||||
(defn- view-internal
|
(defn- view-internal
|
||||||
[{:keys [scroll-enabled? on-scroll close theme]}]
|
[{:keys [scroll-enabled? on-scroll close theme]}]
|
||||||
|
@ -70,6 +91,10 @@
|
||||||
selected-contacts-count (rf/sub [:selected-contacts-count])
|
selected-contacts-count (rf/sub [:selected-contacts-count])
|
||||||
selected-contacts (rf/sub [:group/selected-contacts])
|
selected-contacts (rf/sub [:group/selected-contacts])
|
||||||
one-contact-selected? (= selected-contacts-count 1)
|
one-contact-selected? (= selected-contacts-count 1)
|
||||||
|
[has-error? set-has-error] (rn/use-state false)
|
||||||
|
render-fn (rn/use-callback (fn [item]
|
||||||
|
(contact-item-render item set-has-error))
|
||||||
|
[set-has-error])
|
||||||
contacts-selected? (pos? selected-contacts-count)
|
contacts-selected? (pos? selected-contacts-count)
|
||||||
{:keys [primary-name public-key]} (when one-contact-selected?
|
{:keys [primary-name public-key]} (when one-contact-selected?
|
||||||
(rf/sub [:contacts/contact-by-identity
|
(rf/sub [:contacts/contact-by-identity
|
||||||
|
@ -92,10 +117,12 @@
|
||||||
{:size :paragraph-2
|
{:size :paragraph-2
|
||||||
:weight :regular
|
:weight :regular
|
||||||
:style {:margin-bottom 2
|
:style {:margin-bottom 2
|
||||||
:color (colors/theme-colors colors/neutral-40 colors/neutral-50 theme)}}
|
:color (if has-error?
|
||||||
|
(colors/theme-colors colors/danger-50 colors/danger-60 theme)
|
||||||
|
(colors/theme-colors colors/neutral-40 colors/neutral-50 theme))}}
|
||||||
(i18n/label :t/selected-count-from-max
|
(i18n/label :t/selected-count-from-max
|
||||||
{:selected selected-contacts-count
|
{:selected selected-contacts-count
|
||||||
:max constants/max-group-chat-participants})])]]
|
:max contacts-selection-limit})])]]
|
||||||
(if (empty? contacts)
|
(if (empty? contacts)
|
||||||
[no-contacts-view {:theme theme}]
|
[no-contacts-view {:theme theme}]
|
||||||
[gesture/section-list
|
[gesture/section-list
|
||||||
|
@ -104,7 +131,7 @@
|
||||||
:sections (rf/sub [:contacts/filtered-active-sections])
|
:sections (rf/sub [:contacts/filtered-active-sections])
|
||||||
:render-section-header-fn contact-list/contacts-section-header
|
:render-section-header-fn contact-list/contacts-section-header
|
||||||
:content-container-style {:padding-bottom 70}
|
:content-container-style {:padding-bottom 70}
|
||||||
:render-fn contact-item-render
|
:render-fn render-fn
|
||||||
:scroll-enabled @scroll-enabled?
|
:scroll-enabled @scroll-enabled?
|
||||||
:on-scroll on-scroll}])
|
:on-scroll on-scroll}])
|
||||||
(when contacts-selected?
|
(when contacts-selected?
|
||||||
|
|
|
@ -1037,6 +1037,7 @@
|
||||||
"new-contract": "New Contract",
|
"new-contract": "New Contract",
|
||||||
"new-group": "New group",
|
"new-group": "New group",
|
||||||
"new-group-chat": "New group chat",
|
"new-group-chat": "New group chat",
|
||||||
|
"new-group-limit": "You can only add {{max-contacts}} contacts to the group chat",
|
||||||
"new-network": "New network",
|
"new-network": "New network",
|
||||||
"new-pin-description": "Enter new 6-digit passcode",
|
"new-pin-description": "Enter new 6-digit passcode",
|
||||||
"new-puk-description": "Enter new 12-digit PUK",
|
"new-puk-description": "Enter new 12-digit PUK",
|
||||||
|
|
Loading…
Reference in New Issue